﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;

namespace QLNHK.BLL
{
	public partial class NhanKhau : Ent_Base, ICloneable
	{
        #region Variables
        
		private long _iD;
		private string _maNhanKhau = string.Empty;
		private string _hoLot = string.Empty;
		private string _ten = string.Empty;
		private string _tenGoiKhac = string.Empty;
		private int _gioiTinh;
		private bool _laChuHo;
		private int _quanHeVoiChuHoID;
		private int _ngaySinh;
		private int _thangSinh;
		private int _namSinh;
		private string _noiSinh = string.Empty;
		private int _queQuanTinhTPID;
		private int _queQuanQuanHuyenID;
		private int _queQuanXaPhuongID;
		private int _queQuanToID;
		private int _danTocID;
		private int _quocTichID;
		private int _tonGiaoID;
		private string _soCMND = string.Empty;
		private DateTime _ngayCapCMND = new DateTime(1753, 1, 1);
		private string _noiCapCMND = string.Empty;
		private string _soHoChieu = string.Empty;
		private DateTime _ngayCapHoChieu = new DateTime(1753, 1, 1);
		private string _noiCapHoChieu = string.Empty;
		private DateTime _ngayHetHanHoChieu = new DateTime(1753, 1, 1);
		private int _thuongTruTinhTPID;
		private int _thuongTruQuanHuyenID;
		private int _thuongTruXaPhuongID;
		private int _thuongTruToID;
		private string _thuongTruDiaChi = string.Empty;
		private int _noiOHienNayTinhTPID;
		private int _noiOHienNayQuanHuyenID;
		private int _noiOHienNayXaPhuongID;
		private int _noiOHienNayToID;
		private string _noiOHienNayDiaChi = string.Empty;
		private int _trinhDoHocVanID;
		private int _trinhDoChuyenMonID;
		private int _bietTiengDanTocID;
		private int _trinhDoNgoaiNguID;
		private string _ngheNghiepNoiLamViec = string.Empty;
		private string _soDienThoaiLienHe = string.Empty;
		private int _tinhTrang;
		private DateTime _ngayChuyenDen = new DateTime(1753, 1, 1);
		private string _noiThuongTruTruocChuyenDen = string.Empty;
		private DateTime _ngayChuyenDi = new DateTime(1753, 1, 1);
		private string _noiChuyenDen = string.Empty;
		private DateTime _ngayMat = new DateTime(1753, 1, 1);
		private bool _isDelete;
		private string _lyDoXoaDangKyThuongTru = string.Empty;
		private int _hoKhauID;
        
        #endregion
    
        //---------------------------------------------------------------------------------------------
        
		#region Properties.
		
		public long ID 
        { 
            get { return  _iD; } 
            set
            {
                _iD = value;
                OnPropertyChanged("ID");
            }
        }
		public string MaNhanKhau 
        { 
            get { return  _maNhanKhau; } 
            set
            {
                _maNhanKhau = value;
                OnPropertyChanged("MaNhanKhau");
            }
        }
		public string HoLot 
        { 
            get { return  _hoLot; } 
            set
            {
                _hoLot = value;
                OnPropertyChanged("HoLot");
            }
        }
		public string Ten 
        { 
            get { return  _ten; } 
            set
            {
                _ten = value;
                OnPropertyChanged("Ten");
            }
        }
		public string TenGoiKhac 
        { 
            get { return  _tenGoiKhac; } 
            set
            {
                _tenGoiKhac = value;
                OnPropertyChanged("TenGoiKhac");
            }
        }
		public int GioiTinh 
        { 
            get { return  _gioiTinh; } 
            set
            {
                _gioiTinh = value;
                OnPropertyChanged("GioiTinh");
            }
        }
		public bool LaChuHo 
        { 
            get { return  _laChuHo; } 
            set
            {
                _laChuHo = value;
                OnPropertyChanged("LaChuHo");
            }
        }
		public int QuanHeVoiChuHoID 
        { 
            get { return  _quanHeVoiChuHoID; } 
            set
            {
                _quanHeVoiChuHoID = value;
                OnPropertyChanged("QuanHeVoiChuHoID");
            }
        }
		public int NgaySinh 
        { 
            get { return  _ngaySinh; } 
            set
            {
                _ngaySinh = value;
                OnPropertyChanged("NgaySinh");
            }
        }
		public int ThangSinh 
        { 
            get { return  _thangSinh; } 
            set
            {
                _thangSinh = value;
                OnPropertyChanged("ThangSinh");
            }
        }
		public int NamSinh 
        { 
            get { return  _namSinh; } 
            set
            {
                _namSinh = value;
                OnPropertyChanged("NamSinh");
            }
        }
		public string NoiSinh 
        { 
            get { return  _noiSinh; } 
            set
            {
                _noiSinh = value;
                OnPropertyChanged("NoiSinh");
            }
        }
		public int QueQuanTinhTPID 
        { 
            get { return  _queQuanTinhTPID; } 
            set
            {
                _queQuanTinhTPID = value;
                OnPropertyChanged("QueQuanTinhTPID");
            }
        }
		public int QueQuanQuanHuyenID 
        { 
            get { return  _queQuanQuanHuyenID; } 
            set
            {
                _queQuanQuanHuyenID = value;
                OnPropertyChanged("QueQuanQuanHuyenID");
            }
        }
		public int QueQuanXaPhuongID 
        { 
            get { return  _queQuanXaPhuongID; } 
            set
            {
                _queQuanXaPhuongID = value;
                OnPropertyChanged("QueQuanXaPhuongID");
            }
        }
		public int QueQuanToID 
        { 
            get { return  _queQuanToID; } 
            set
            {
                _queQuanToID = value;
                OnPropertyChanged("QueQuanToID");
            }
        }
		public int DanTocID 
        { 
            get { return  _danTocID; } 
            set
            {
                _danTocID = value;
                OnPropertyChanged("DanTocID");
            }
        }
		public int QuocTichID 
        { 
            get { return  _quocTichID; } 
            set
            {
                _quocTichID = value;
                OnPropertyChanged("QuocTichID");
            }
        }
		public int TonGiaoID 
        { 
            get { return  _tonGiaoID; } 
            set
            {
                _tonGiaoID = value;
                OnPropertyChanged("TonGiaoID");
            }
        }
		public string SoCMND 
        { 
            get { return  _soCMND; } 
            set
            {
                _soCMND = value;
                OnPropertyChanged("SoCMND");
            }
        }
		public DateTime NgayCapCMND 
        { 
            get { return  _ngayCapCMND; } 
            set
            {
                _ngayCapCMND = value;
                OnPropertyChanged("NgayCapCMND");
            }
        }
		public string NoiCapCMND 
        { 
            get { return  _noiCapCMND; } 
            set
            {
                _noiCapCMND = value;
                OnPropertyChanged("NoiCapCMND");
            }
        }
		public string SoHoChieu 
        { 
            get { return  _soHoChieu; } 
            set
            {
                _soHoChieu = value;
                OnPropertyChanged("SoHoChieu");
            }
        }
		public DateTime NgayCapHoChieu 
        { 
            get { return  _ngayCapHoChieu; } 
            set
            {
                _ngayCapHoChieu = value;
                OnPropertyChanged("NgayCapHoChieu");
            }
        }
		public string NoiCapHoChieu 
        { 
            get { return  _noiCapHoChieu; } 
            set
            {
                _noiCapHoChieu = value;
                OnPropertyChanged("NoiCapHoChieu");
            }
        }
		public DateTime NgayHetHanHoChieu 
        { 
            get { return  _ngayHetHanHoChieu; } 
            set
            {
                _ngayHetHanHoChieu = value;
                OnPropertyChanged("NgayHetHanHoChieu");
            }
        }
		public int ThuongTruTinhTPID 
        { 
            get { return  _thuongTruTinhTPID; } 
            set
            {
                _thuongTruTinhTPID = value;
                OnPropertyChanged("ThuongTruTinhTPID");
            }
        }
		public int ThuongTruQuanHuyenID 
        { 
            get { return  _thuongTruQuanHuyenID; } 
            set
            {
                _thuongTruQuanHuyenID = value;
                OnPropertyChanged("ThuongTruQuanHuyenID");
            }
        }
		public int ThuongTruXaPhuongID 
        { 
            get { return  _thuongTruXaPhuongID; } 
            set
            {
                _thuongTruXaPhuongID = value;
                OnPropertyChanged("ThuongTruXaPhuongID");
            }
        }
		public int ThuongTruToID 
        { 
            get { return  _thuongTruToID; } 
            set
            {
                _thuongTruToID = value;
                OnPropertyChanged("ThuongTruToID");
            }
        }
		public string ThuongTruDiaChi 
        { 
            get { return  _thuongTruDiaChi; } 
            set
            {
                _thuongTruDiaChi = value;
                OnPropertyChanged("ThuongTruDiaChi");
            }
        }
		public int NoiOHienNayTinhTPID 
        { 
            get { return  _noiOHienNayTinhTPID; } 
            set
            {
                _noiOHienNayTinhTPID = value;
                OnPropertyChanged("NoiOHienNayTinhTPID");
            }
        }
		public int NoiOHienNayQuanHuyenID 
        { 
            get { return  _noiOHienNayQuanHuyenID; } 
            set
            {
                _noiOHienNayQuanHuyenID = value;
                OnPropertyChanged("NoiOHienNayQuanHuyenID");
            }
        }
		public int NoiOHienNayXaPhuongID 
        { 
            get { return  _noiOHienNayXaPhuongID; } 
            set
            {
                _noiOHienNayXaPhuongID = value;
                OnPropertyChanged("NoiOHienNayXaPhuongID");
            }
        }
		public int NoiOHienNayToID 
        { 
            get { return  _noiOHienNayToID; } 
            set
            {
                _noiOHienNayToID = value;
                OnPropertyChanged("NoiOHienNayToID");
            }
        }
		public string NoiOHienNayDiaChi 
        { 
            get { return  _noiOHienNayDiaChi; } 
            set
            {
                _noiOHienNayDiaChi = value;
                OnPropertyChanged("NoiOHienNayDiaChi");
            }
        }
		public int TrinhDoHocVanID 
        { 
            get { return  _trinhDoHocVanID; } 
            set
            {
                _trinhDoHocVanID = value;
                OnPropertyChanged("TrinhDoHocVanID");
            }
        }
		public int TrinhDoChuyenMonID 
        { 
            get { return  _trinhDoChuyenMonID; } 
            set
            {
                _trinhDoChuyenMonID = value;
                OnPropertyChanged("TrinhDoChuyenMonID");
            }
        }
		public int BietTiengDanTocID 
        { 
            get { return  _bietTiengDanTocID; } 
            set
            {
                _bietTiengDanTocID = value;
                OnPropertyChanged("BietTiengDanTocID");
            }
        }
		public int TrinhDoNgoaiNguID 
        { 
            get { return  _trinhDoNgoaiNguID; } 
            set
            {
                _trinhDoNgoaiNguID = value;
                OnPropertyChanged("TrinhDoNgoaiNguID");
            }
        }
		public string NgheNghiepNoiLamViec 
        { 
            get { return  _ngheNghiepNoiLamViec; } 
            set
            {
                _ngheNghiepNoiLamViec = value;
                OnPropertyChanged("NgheNghiepNoiLamViec");
            }
        }
		public string SoDienThoaiLienHe 
        { 
            get { return  _soDienThoaiLienHe; } 
            set
            {
                _soDienThoaiLienHe = value;
                OnPropertyChanged("SoDienThoaiLienHe");
            }
        }
		public int TinhTrang 
        { 
            get { return  _tinhTrang; } 
            set
            {
                _tinhTrang = value;
                OnPropertyChanged("TinhTrang");
            }
        }
		public DateTime NgayChuyenDen 
        { 
            get { return  _ngayChuyenDen; } 
            set
            {
                _ngayChuyenDen = value;
                OnPropertyChanged("NgayChuyenDen");
            }
        }
		public string NoiThuongTruTruocChuyenDen 
        { 
            get { return  _noiThuongTruTruocChuyenDen; } 
            set
            {
                _noiThuongTruTruocChuyenDen = value;
                OnPropertyChanged("NoiThuongTruTruocChuyenDen");
            }
        }
		public DateTime NgayChuyenDi 
        { 
            get { return  _ngayChuyenDi; } 
            set
            {
                _ngayChuyenDi = value;
                OnPropertyChanged("NgayChuyenDi");
            }
        }
		public string NoiChuyenDen 
        { 
            get { return  _noiChuyenDen; } 
            set
            {
                _noiChuyenDen = value;
                OnPropertyChanged("NoiChuyenDen");
            }
        }
		public DateTime NgayMat 
        { 
            get { return  _ngayMat; } 
            set
            {
                _ngayMat = value;
                OnPropertyChanged("NgayMat");
            }
        }
		public bool IsDelete 
        { 
            get { return  _isDelete; } 
            set
            {
                _isDelete = value;
                OnPropertyChanged("IsDelete");
            }
        }
		public string LyDoXoaDangKyThuongTru 
        { 
            get { return  _lyDoXoaDangKyThuongTru; } 
            set
            {
                _lyDoXoaDangKyThuongTru = value;
                OnPropertyChanged("LyDoXoaDangKyThuongTru");
            }
        }
		public int HoKhauID 
        { 
            get { return  _hoKhauID; } 
            set
            {
                _hoKhauID = value;
                OnPropertyChanged("HoKhauID");
            }
        }
		
		#endregion
		
		//---------------------------------------------------------------------------------------------
		
		#region Methods
		protected static List<NhanKhau> ConvertToCollection(IDataReader reader)
		{
			List<NhanKhau> collection = new List<NhanKhau>();
			while (reader.Read())
			{
				NhanKhau entity = new NhanKhau();
				if (!reader.IsDBNull(reader.GetOrdinal("ID"))) entity.ID = reader.GetInt64(reader.GetOrdinal("ID"));
				if (!reader.IsDBNull(reader.GetOrdinal("MaNhanKhau"))) entity.MaNhanKhau = reader.GetString(reader.GetOrdinal("MaNhanKhau"));
				if (!reader.IsDBNull(reader.GetOrdinal("HoLot"))) entity.HoLot = reader.GetString(reader.GetOrdinal("HoLot"));
				if (!reader.IsDBNull(reader.GetOrdinal("Ten"))) entity.Ten = reader.GetString(reader.GetOrdinal("Ten"));
				if (!reader.IsDBNull(reader.GetOrdinal("TenGoiKhac"))) entity.TenGoiKhac = reader.GetString(reader.GetOrdinal("TenGoiKhac"));
				if (!reader.IsDBNull(reader.GetOrdinal("GioiTinh"))) entity.GioiTinh = reader.GetInt32(reader.GetOrdinal("GioiTinh"));
				if (!reader.IsDBNull(reader.GetOrdinal("LaChuHo"))) entity.LaChuHo = reader.GetBoolean(reader.GetOrdinal("LaChuHo"));
				if (!reader.IsDBNull(reader.GetOrdinal("QuanHeVoiChuHoID"))) entity.QuanHeVoiChuHoID = reader.GetInt32(reader.GetOrdinal("QuanHeVoiChuHoID"));
				if (!reader.IsDBNull(reader.GetOrdinal("NgaySinh"))) entity.NgaySinh = reader.GetInt32(reader.GetOrdinal("NgaySinh"));
				if (!reader.IsDBNull(reader.GetOrdinal("ThangSinh"))) entity.ThangSinh = reader.GetInt32(reader.GetOrdinal("ThangSinh"));
				if (!reader.IsDBNull(reader.GetOrdinal("NamSinh"))) entity.NamSinh = reader.GetInt32(reader.GetOrdinal("NamSinh"));
				if (!reader.IsDBNull(reader.GetOrdinal("NoiSinh"))) entity.NoiSinh = reader.GetString(reader.GetOrdinal("NoiSinh"));
				if (!reader.IsDBNull(reader.GetOrdinal("QueQuanTinhTPID"))) entity.QueQuanTinhTPID = reader.GetInt32(reader.GetOrdinal("QueQuanTinhTPID"));
				if (!reader.IsDBNull(reader.GetOrdinal("QueQuanQuanHuyenID"))) entity.QueQuanQuanHuyenID = reader.GetInt32(reader.GetOrdinal("QueQuanQuanHuyenID"));
				if (!reader.IsDBNull(reader.GetOrdinal("QueQuanXaPhuongID"))) entity.QueQuanXaPhuongID = reader.GetInt32(reader.GetOrdinal("QueQuanXaPhuongID"));
				if (!reader.IsDBNull(reader.GetOrdinal("QueQuanToID"))) entity.QueQuanToID = reader.GetInt32(reader.GetOrdinal("QueQuanToID"));
				if (!reader.IsDBNull(reader.GetOrdinal("DanTocID"))) entity.DanTocID = reader.GetInt32(reader.GetOrdinal("DanTocID"));
				if (!reader.IsDBNull(reader.GetOrdinal("QuocTichID"))) entity.QuocTichID = reader.GetInt32(reader.GetOrdinal("QuocTichID"));
				if (!reader.IsDBNull(reader.GetOrdinal("TonGiaoID"))) entity.TonGiaoID = reader.GetInt32(reader.GetOrdinal("TonGiaoID"));
				if (!reader.IsDBNull(reader.GetOrdinal("SoCMND"))) entity.SoCMND = reader.GetString(reader.GetOrdinal("SoCMND"));
				if (!reader.IsDBNull(reader.GetOrdinal("NgayCapCMND"))) entity.NgayCapCMND = reader.GetDateTime(reader.GetOrdinal("NgayCapCMND"));
				if (!reader.IsDBNull(reader.GetOrdinal("NoiCapCMND"))) entity.NoiCapCMND = reader.GetString(reader.GetOrdinal("NoiCapCMND"));
				if (!reader.IsDBNull(reader.GetOrdinal("SoHoChieu"))) entity.SoHoChieu = reader.GetString(reader.GetOrdinal("SoHoChieu"));
				if (!reader.IsDBNull(reader.GetOrdinal("NgayCapHoChieu"))) entity.NgayCapHoChieu = reader.GetDateTime(reader.GetOrdinal("NgayCapHoChieu"));
				if (!reader.IsDBNull(reader.GetOrdinal("NoiCapHoChieu"))) entity.NoiCapHoChieu = reader.GetString(reader.GetOrdinal("NoiCapHoChieu"));
				if (!reader.IsDBNull(reader.GetOrdinal("NgayHetHanHoChieu"))) entity.NgayHetHanHoChieu = reader.GetDateTime(reader.GetOrdinal("NgayHetHanHoChieu"));
				if (!reader.IsDBNull(reader.GetOrdinal("ThuongTruTinhTPID"))) entity.ThuongTruTinhTPID = reader.GetInt32(reader.GetOrdinal("ThuongTruTinhTPID"));
				if (!reader.IsDBNull(reader.GetOrdinal("ThuongTruQuanHuyenID"))) entity.ThuongTruQuanHuyenID = reader.GetInt32(reader.GetOrdinal("ThuongTruQuanHuyenID"));
				if (!reader.IsDBNull(reader.GetOrdinal("ThuongTruXaPhuongID"))) entity.ThuongTruXaPhuongID = reader.GetInt32(reader.GetOrdinal("ThuongTruXaPhuongID"));
				if (!reader.IsDBNull(reader.GetOrdinal("ThuongTruToID"))) entity.ThuongTruToID = reader.GetInt32(reader.GetOrdinal("ThuongTruToID"));
				if (!reader.IsDBNull(reader.GetOrdinal("ThuongTruDiaChi"))) entity.ThuongTruDiaChi = reader.GetString(reader.GetOrdinal("ThuongTruDiaChi"));
				if (!reader.IsDBNull(reader.GetOrdinal("NoiOHienNayTinhTPID"))) entity.NoiOHienNayTinhTPID = reader.GetInt32(reader.GetOrdinal("NoiOHienNayTinhTPID"));
				if (!reader.IsDBNull(reader.GetOrdinal("NoiOHienNayQuanHuyenID"))) entity.NoiOHienNayQuanHuyenID = reader.GetInt32(reader.GetOrdinal("NoiOHienNayQuanHuyenID"));
				if (!reader.IsDBNull(reader.GetOrdinal("NoiOHienNayXaPhuongID"))) entity.NoiOHienNayXaPhuongID = reader.GetInt32(reader.GetOrdinal("NoiOHienNayXaPhuongID"));
				if (!reader.IsDBNull(reader.GetOrdinal("NoiOHienNayToID"))) entity.NoiOHienNayToID = reader.GetInt32(reader.GetOrdinal("NoiOHienNayToID"));
				if (!reader.IsDBNull(reader.GetOrdinal("NoiOHienNayDiaChi"))) entity.NoiOHienNayDiaChi = reader.GetString(reader.GetOrdinal("NoiOHienNayDiaChi"));
				if (!reader.IsDBNull(reader.GetOrdinal("TrinhDoHocVanID"))) entity.TrinhDoHocVanID = reader.GetInt32(reader.GetOrdinal("TrinhDoHocVanID"));
				if (!reader.IsDBNull(reader.GetOrdinal("TrinhDoChuyenMonID"))) entity.TrinhDoChuyenMonID = reader.GetInt32(reader.GetOrdinal("TrinhDoChuyenMonID"));
				if (!reader.IsDBNull(reader.GetOrdinal("BietTiengDanTocID"))) entity.BietTiengDanTocID = reader.GetInt32(reader.GetOrdinal("BietTiengDanTocID"));
				if (!reader.IsDBNull(reader.GetOrdinal("TrinhDoNgoaiNguID"))) entity.TrinhDoNgoaiNguID = reader.GetInt32(reader.GetOrdinal("TrinhDoNgoaiNguID"));
				if (!reader.IsDBNull(reader.GetOrdinal("NgheNghiepNoiLamViec"))) entity.NgheNghiepNoiLamViec = reader.GetString(reader.GetOrdinal("NgheNghiepNoiLamViec"));
				if (!reader.IsDBNull(reader.GetOrdinal("SoDienThoaiLienHe"))) entity.SoDienThoaiLienHe = reader.GetString(reader.GetOrdinal("SoDienThoaiLienHe"));
				if (!reader.IsDBNull(reader.GetOrdinal("TinhTrang"))) entity.TinhTrang = reader.GetInt32(reader.GetOrdinal("TinhTrang"));
				if (!reader.IsDBNull(reader.GetOrdinal("NgayChuyenDen"))) entity.NgayChuyenDen = reader.GetDateTime(reader.GetOrdinal("NgayChuyenDen"));
				if (!reader.IsDBNull(reader.GetOrdinal("NoiThuongTruTruocChuyenDen"))) entity.NoiThuongTruTruocChuyenDen = reader.GetString(reader.GetOrdinal("NoiThuongTruTruocChuyenDen"));
				if (!reader.IsDBNull(reader.GetOrdinal("NgayChuyenDi"))) entity.NgayChuyenDi = reader.GetDateTime(reader.GetOrdinal("NgayChuyenDi"));
				if (!reader.IsDBNull(reader.GetOrdinal("NoiChuyenDen"))) entity.NoiChuyenDen = reader.GetString(reader.GetOrdinal("NoiChuyenDen"));
				if (!reader.IsDBNull(reader.GetOrdinal("NgayMat"))) entity.NgayMat = reader.GetDateTime(reader.GetOrdinal("NgayMat"));
				if (!reader.IsDBNull(reader.GetOrdinal("IsDelete"))) entity.IsDelete = reader.GetBoolean(reader.GetOrdinal("IsDelete"));
				if (!reader.IsDBNull(reader.GetOrdinal("LyDoXoaDangKyThuongTru"))) entity.LyDoXoaDangKyThuongTru = reader.GetString(reader.GetOrdinal("LyDoXoaDangKyThuongTru"));
				if (!reader.IsDBNull(reader.GetOrdinal("HoKhauID"))) entity.HoKhauID = reader.GetInt32(reader.GetOrdinal("HoKhauID"));
				collection.Add(entity);
			}
			reader.Close();
			return collection;
		}
		
		public static bool Find(List<NhanKhau> collection, long iD)
        {
            foreach (NhanKhau item in collection)
            {
                if (item.ID == iD)
                {
                    return true;
                }
            }

            return false;
        }
		
		public static void UpdateDataSet(DataSet ds)
        {
            string insert = "Insert INTO t_NhanKhau VALUES(@MaNhanKhau, @HoLot, @Ten, @TenGoiKhac, @GioiTinh, @LaChuHo, @QuanHeVoiChuHoID, @NgaySinh, @ThangSinh, @NamSinh, @NoiSinh, @QueQuanTinhTPID, @QueQuanQuanHuyenID, @QueQuanXaPhuongID, @QueQuanToID, @DanTocID, @QuocTichID, @TonGiaoID, @SoCMND, @NgayCapCMND, @NoiCapCMND, @SoHoChieu, @NgayCapHoChieu, @NoiCapHoChieu, @NgayHetHanHoChieu, @ThuongTruTinhTPID, @ThuongTruQuanHuyenID, @ThuongTruXaPhuongID, @ThuongTruToID, @ThuongTruDiaChi, @NoiOHienNayTinhTPID, @NoiOHienNayQuanHuyenID, @NoiOHienNayXaPhuongID, @NoiOHienNayToID, @NoiOHienNayDiaChi, @TrinhDoHocVanID, @TrinhDoChuyenMonID, @BietTiengDanTocID, @TrinhDoNgoaiNguID, @NgheNghiepNoiLamViec, @SoDienThoaiLienHe, @TinhTrang, @NgayChuyenDen, @NoiThuongTruTruocChuyenDen, @NgayChuyenDi, @NoiChuyenDen, @NgayMat, @IsDelete, @LyDoXoaDangKyThuongTru, @HoKhauID)";
            string update = "UPDATE t_NhanKhau SET MaNhanKhau = @MaNhanKhau, HoLot = @HoLot, Ten = @Ten, TenGoiKhac = @TenGoiKhac, GioiTinh = @GioiTinh, LaChuHo = @LaChuHo, QuanHeVoiChuHoID = @QuanHeVoiChuHoID, NgaySinh = @NgaySinh, ThangSinh = @ThangSinh, NamSinh = @NamSinh, NoiSinh = @NoiSinh, QueQuanTinhTPID = @QueQuanTinhTPID, QueQuanQuanHuyenID = @QueQuanQuanHuyenID, QueQuanXaPhuongID = @QueQuanXaPhuongID, QueQuanToID = @QueQuanToID, DanTocID = @DanTocID, QuocTichID = @QuocTichID, TonGiaoID = @TonGiaoID, SoCMND = @SoCMND, NgayCapCMND = @NgayCapCMND, NoiCapCMND = @NoiCapCMND, SoHoChieu = @SoHoChieu, NgayCapHoChieu = @NgayCapHoChieu, NoiCapHoChieu = @NoiCapHoChieu, NgayHetHanHoChieu = @NgayHetHanHoChieu, ThuongTruTinhTPID = @ThuongTruTinhTPID, ThuongTruQuanHuyenID = @ThuongTruQuanHuyenID, ThuongTruXaPhuongID = @ThuongTruXaPhuongID, ThuongTruToID = @ThuongTruToID, ThuongTruDiaChi = @ThuongTruDiaChi, NoiOHienNayTinhTPID = @NoiOHienNayTinhTPID, NoiOHienNayQuanHuyenID = @NoiOHienNayQuanHuyenID, NoiOHienNayXaPhuongID = @NoiOHienNayXaPhuongID, NoiOHienNayToID = @NoiOHienNayToID, NoiOHienNayDiaChi = @NoiOHienNayDiaChi, TrinhDoHocVanID = @TrinhDoHocVanID, TrinhDoChuyenMonID = @TrinhDoChuyenMonID, BietTiengDanTocID = @BietTiengDanTocID, TrinhDoNgoaiNguID = @TrinhDoNgoaiNguID, NgheNghiepNoiLamViec = @NgheNghiepNoiLamViec, SoDienThoaiLienHe = @SoDienThoaiLienHe, TinhTrang = @TinhTrang, NgayChuyenDen = @NgayChuyenDen, NoiThuongTruTruocChuyenDen = @NoiThuongTruTruocChuyenDen, NgayChuyenDi = @NgayChuyenDi, NoiChuyenDen = @NoiChuyenDen, NgayMat = @NgayMat, IsDelete = @IsDelete, LyDoXoaDangKyThuongTru = @LyDoXoaDangKyThuongTru, HoKhauID = @HoKhauID WHERE ID = @ID";
            string delete = "DELETE FROM t_NhanKhau WHERE ID = @ID";

			SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();

            System.Data.Common.DbCommand InsertCommand = db.GetSqlStringCommand(insert);
			db.AddInParameter(InsertCommand, "@ID", SqlDbType.BigInt, "ID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@MaNhanKhau", SqlDbType.VarChar, "MaNhanKhau", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@HoLot", SqlDbType.NVarChar, "HoLot", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@Ten", SqlDbType.NVarChar, "Ten", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@TenGoiKhac", SqlDbType.NVarChar, "TenGoiKhac", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@GioiTinh", SqlDbType.Int, "GioiTinh", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@LaChuHo", SqlDbType.Bit, "LaChuHo", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@QuanHeVoiChuHoID", SqlDbType.Int, "QuanHeVoiChuHoID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NgaySinh", SqlDbType.Int, "NgaySinh", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@ThangSinh", SqlDbType.Int, "ThangSinh", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NamSinh", SqlDbType.Int, "NamSinh", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NoiSinh", SqlDbType.NVarChar, "NoiSinh", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@QueQuanTinhTPID", SqlDbType.Int, "QueQuanTinhTPID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@QueQuanQuanHuyenID", SqlDbType.Int, "QueQuanQuanHuyenID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@QueQuanXaPhuongID", SqlDbType.Int, "QueQuanXaPhuongID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@QueQuanToID", SqlDbType.Int, "QueQuanToID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@DanTocID", SqlDbType.Int, "DanTocID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@QuocTichID", SqlDbType.Int, "QuocTichID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@TonGiaoID", SqlDbType.Int, "TonGiaoID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@SoCMND", SqlDbType.VarChar, "SoCMND", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NgayCapCMND", SqlDbType.DateTime, "NgayCapCMND", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NoiCapCMND", SqlDbType.NVarChar, "NoiCapCMND", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@SoHoChieu", SqlDbType.VarChar, "SoHoChieu", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NgayCapHoChieu", SqlDbType.DateTime, "NgayCapHoChieu", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NoiCapHoChieu", SqlDbType.NVarChar, "NoiCapHoChieu", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NgayHetHanHoChieu", SqlDbType.DateTime, "NgayHetHanHoChieu", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@ThuongTruTinhTPID", SqlDbType.Int, "ThuongTruTinhTPID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@ThuongTruQuanHuyenID", SqlDbType.Int, "ThuongTruQuanHuyenID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@ThuongTruXaPhuongID", SqlDbType.Int, "ThuongTruXaPhuongID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@ThuongTruToID", SqlDbType.Int, "ThuongTruToID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@ThuongTruDiaChi", SqlDbType.NVarChar, "ThuongTruDiaChi", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NoiOHienNayTinhTPID", SqlDbType.Int, "NoiOHienNayTinhTPID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NoiOHienNayQuanHuyenID", SqlDbType.Int, "NoiOHienNayQuanHuyenID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NoiOHienNayXaPhuongID", SqlDbType.Int, "NoiOHienNayXaPhuongID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NoiOHienNayToID", SqlDbType.Int, "NoiOHienNayToID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NoiOHienNayDiaChi", SqlDbType.NVarChar, "NoiOHienNayDiaChi", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@TrinhDoHocVanID", SqlDbType.Int, "TrinhDoHocVanID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@TrinhDoChuyenMonID", SqlDbType.Int, "TrinhDoChuyenMonID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@BietTiengDanTocID", SqlDbType.Int, "BietTiengDanTocID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@TrinhDoNgoaiNguID", SqlDbType.Int, "TrinhDoNgoaiNguID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NgheNghiepNoiLamViec", SqlDbType.NVarChar, "NgheNghiepNoiLamViec", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@SoDienThoaiLienHe", SqlDbType.VarChar, "SoDienThoaiLienHe", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@TinhTrang", SqlDbType.Int, "TinhTrang", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NgayChuyenDen", SqlDbType.DateTime, "NgayChuyenDen", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NoiThuongTruTruocChuyenDen", SqlDbType.NVarChar, "NoiThuongTruTruocChuyenDen", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NgayChuyenDi", SqlDbType.DateTime, "NgayChuyenDi", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NoiChuyenDen", SqlDbType.NVarChar, "NoiChuyenDen", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NgayMat", SqlDbType.DateTime, "NgayMat", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@IsDelete", SqlDbType.Bit, "IsDelete", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@LyDoXoaDangKyThuongTru", SqlDbType.NVarChar, "LyDoXoaDangKyThuongTru", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@HoKhauID", SqlDbType.Int, "HoKhauID", DataRowVersion.Current);

            System.Data.Common.DbCommand UpdateCommand = db.GetSqlStringCommand(update);
			db.AddInParameter(UpdateCommand, "@ID", SqlDbType.BigInt, "ID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@MaNhanKhau", SqlDbType.VarChar, "MaNhanKhau", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@HoLot", SqlDbType.NVarChar, "HoLot", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@Ten", SqlDbType.NVarChar, "Ten", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@TenGoiKhac", SqlDbType.NVarChar, "TenGoiKhac", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@GioiTinh", SqlDbType.Int, "GioiTinh", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@LaChuHo", SqlDbType.Bit, "LaChuHo", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@QuanHeVoiChuHoID", SqlDbType.Int, "QuanHeVoiChuHoID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NgaySinh", SqlDbType.Int, "NgaySinh", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@ThangSinh", SqlDbType.Int, "ThangSinh", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NamSinh", SqlDbType.Int, "NamSinh", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NoiSinh", SqlDbType.NVarChar, "NoiSinh", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@QueQuanTinhTPID", SqlDbType.Int, "QueQuanTinhTPID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@QueQuanQuanHuyenID", SqlDbType.Int, "QueQuanQuanHuyenID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@QueQuanXaPhuongID", SqlDbType.Int, "QueQuanXaPhuongID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@QueQuanToID", SqlDbType.Int, "QueQuanToID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@DanTocID", SqlDbType.Int, "DanTocID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@QuocTichID", SqlDbType.Int, "QuocTichID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@TonGiaoID", SqlDbType.Int, "TonGiaoID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@SoCMND", SqlDbType.VarChar, "SoCMND", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NgayCapCMND", SqlDbType.DateTime, "NgayCapCMND", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NoiCapCMND", SqlDbType.NVarChar, "NoiCapCMND", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@SoHoChieu", SqlDbType.VarChar, "SoHoChieu", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NgayCapHoChieu", SqlDbType.DateTime, "NgayCapHoChieu", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NoiCapHoChieu", SqlDbType.NVarChar, "NoiCapHoChieu", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NgayHetHanHoChieu", SqlDbType.DateTime, "NgayHetHanHoChieu", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@ThuongTruTinhTPID", SqlDbType.Int, "ThuongTruTinhTPID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@ThuongTruQuanHuyenID", SqlDbType.Int, "ThuongTruQuanHuyenID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@ThuongTruXaPhuongID", SqlDbType.Int, "ThuongTruXaPhuongID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@ThuongTruToID", SqlDbType.Int, "ThuongTruToID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@ThuongTruDiaChi", SqlDbType.NVarChar, "ThuongTruDiaChi", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NoiOHienNayTinhTPID", SqlDbType.Int, "NoiOHienNayTinhTPID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NoiOHienNayQuanHuyenID", SqlDbType.Int, "NoiOHienNayQuanHuyenID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NoiOHienNayXaPhuongID", SqlDbType.Int, "NoiOHienNayXaPhuongID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NoiOHienNayToID", SqlDbType.Int, "NoiOHienNayToID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NoiOHienNayDiaChi", SqlDbType.NVarChar, "NoiOHienNayDiaChi", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@TrinhDoHocVanID", SqlDbType.Int, "TrinhDoHocVanID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@TrinhDoChuyenMonID", SqlDbType.Int, "TrinhDoChuyenMonID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@BietTiengDanTocID", SqlDbType.Int, "BietTiengDanTocID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@TrinhDoNgoaiNguID", SqlDbType.Int, "TrinhDoNgoaiNguID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NgheNghiepNoiLamViec", SqlDbType.NVarChar, "NgheNghiepNoiLamViec", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@SoDienThoaiLienHe", SqlDbType.VarChar, "SoDienThoaiLienHe", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@TinhTrang", SqlDbType.Int, "TinhTrang", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NgayChuyenDen", SqlDbType.DateTime, "NgayChuyenDen", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NoiThuongTruTruocChuyenDen", SqlDbType.NVarChar, "NoiThuongTruTruocChuyenDen", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NgayChuyenDi", SqlDbType.DateTime, "NgayChuyenDi", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NoiChuyenDen", SqlDbType.NVarChar, "NoiChuyenDen", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NgayMat", SqlDbType.DateTime, "NgayMat", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@IsDelete", SqlDbType.Bit, "IsDelete", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@LyDoXoaDangKyThuongTru", SqlDbType.NVarChar, "LyDoXoaDangKyThuongTru", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@HoKhauID", SqlDbType.Int, "HoKhauID", DataRowVersion.Current);
			
            System.Data.Common.DbCommand DeleteCommand = db.GetSqlStringCommand(delete);
			db.AddInParameter(DeleteCommand, "@ID", SqlDbType.BigInt, "ID", DataRowVersion.Current);

            db.UpdateDataSet(ds, ds.Tables[0].TableName, InsertCommand, UpdateCommand, DeleteCommand, UpdateBehavior.Standard);
        }
				
		public static void UpdateDataSet(DataSet ds, string tableName)
        {
            string insert = "Insert INTO t_NhanKhau VALUES(@MaNhanKhau, @HoLot, @Ten, @TenGoiKhac, @GioiTinh, @LaChuHo, @QuanHeVoiChuHoID, @NgaySinh, @ThangSinh, @NamSinh, @NoiSinh, @QueQuanTinhTPID, @QueQuanQuanHuyenID, @QueQuanXaPhuongID, @QueQuanToID, @DanTocID, @QuocTichID, @TonGiaoID, @SoCMND, @NgayCapCMND, @NoiCapCMND, @SoHoChieu, @NgayCapHoChieu, @NoiCapHoChieu, @NgayHetHanHoChieu, @ThuongTruTinhTPID, @ThuongTruQuanHuyenID, @ThuongTruXaPhuongID, @ThuongTruToID, @ThuongTruDiaChi, @NoiOHienNayTinhTPID, @NoiOHienNayQuanHuyenID, @NoiOHienNayXaPhuongID, @NoiOHienNayToID, @NoiOHienNayDiaChi, @TrinhDoHocVanID, @TrinhDoChuyenMonID, @BietTiengDanTocID, @TrinhDoNgoaiNguID, @NgheNghiepNoiLamViec, @SoDienThoaiLienHe, @TinhTrang, @NgayChuyenDen, @NoiThuongTruTruocChuyenDen, @NgayChuyenDi, @NoiChuyenDen, @NgayMat, @IsDelete, @LyDoXoaDangKyThuongTru, @HoKhauID)";
            string update = "UPDATE t_NhanKhau SET MaNhanKhau = @MaNhanKhau, HoLot = @HoLot, Ten = @Ten, TenGoiKhac = @TenGoiKhac, GioiTinh = @GioiTinh, LaChuHo = @LaChuHo, QuanHeVoiChuHoID = @QuanHeVoiChuHoID, NgaySinh = @NgaySinh, ThangSinh = @ThangSinh, NamSinh = @NamSinh, NoiSinh = @NoiSinh, QueQuanTinhTPID = @QueQuanTinhTPID, QueQuanQuanHuyenID = @QueQuanQuanHuyenID, QueQuanXaPhuongID = @QueQuanXaPhuongID, QueQuanToID = @QueQuanToID, DanTocID = @DanTocID, QuocTichID = @QuocTichID, TonGiaoID = @TonGiaoID, SoCMND = @SoCMND, NgayCapCMND = @NgayCapCMND, NoiCapCMND = @NoiCapCMND, SoHoChieu = @SoHoChieu, NgayCapHoChieu = @NgayCapHoChieu, NoiCapHoChieu = @NoiCapHoChieu, NgayHetHanHoChieu = @NgayHetHanHoChieu, ThuongTruTinhTPID = @ThuongTruTinhTPID, ThuongTruQuanHuyenID = @ThuongTruQuanHuyenID, ThuongTruXaPhuongID = @ThuongTruXaPhuongID, ThuongTruToID = @ThuongTruToID, ThuongTruDiaChi = @ThuongTruDiaChi, NoiOHienNayTinhTPID = @NoiOHienNayTinhTPID, NoiOHienNayQuanHuyenID = @NoiOHienNayQuanHuyenID, NoiOHienNayXaPhuongID = @NoiOHienNayXaPhuongID, NoiOHienNayToID = @NoiOHienNayToID, NoiOHienNayDiaChi = @NoiOHienNayDiaChi, TrinhDoHocVanID = @TrinhDoHocVanID, TrinhDoChuyenMonID = @TrinhDoChuyenMonID, BietTiengDanTocID = @BietTiengDanTocID, TrinhDoNgoaiNguID = @TrinhDoNgoaiNguID, NgheNghiepNoiLamViec = @NgheNghiepNoiLamViec, SoDienThoaiLienHe = @SoDienThoaiLienHe, TinhTrang = @TinhTrang, NgayChuyenDen = @NgayChuyenDen, NoiThuongTruTruocChuyenDen = @NoiThuongTruTruocChuyenDen, NgayChuyenDi = @NgayChuyenDi, NoiChuyenDen = @NoiChuyenDen, NgayMat = @NgayMat, IsDelete = @IsDelete, LyDoXoaDangKyThuongTru = @LyDoXoaDangKyThuongTru, HoKhauID = @HoKhauID WHERE ID = @ID";
            string delete = "DELETE FROM t_NhanKhau WHERE ID = @ID";

			SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();

            System.Data.Common.DbCommand InsertCommand = db.GetSqlStringCommand(insert);
			db.AddInParameter(InsertCommand, "@ID", SqlDbType.BigInt, "ID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@MaNhanKhau", SqlDbType.VarChar, "MaNhanKhau", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@HoLot", SqlDbType.NVarChar, "HoLot", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@Ten", SqlDbType.NVarChar, "Ten", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@TenGoiKhac", SqlDbType.NVarChar, "TenGoiKhac", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@GioiTinh", SqlDbType.Int, "GioiTinh", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@LaChuHo", SqlDbType.Bit, "LaChuHo", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@QuanHeVoiChuHoID", SqlDbType.Int, "QuanHeVoiChuHoID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NgaySinh", SqlDbType.Int, "NgaySinh", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@ThangSinh", SqlDbType.Int, "ThangSinh", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NamSinh", SqlDbType.Int, "NamSinh", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NoiSinh", SqlDbType.NVarChar, "NoiSinh", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@QueQuanTinhTPID", SqlDbType.Int, "QueQuanTinhTPID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@QueQuanQuanHuyenID", SqlDbType.Int, "QueQuanQuanHuyenID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@QueQuanXaPhuongID", SqlDbType.Int, "QueQuanXaPhuongID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@QueQuanToID", SqlDbType.Int, "QueQuanToID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@DanTocID", SqlDbType.Int, "DanTocID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@QuocTichID", SqlDbType.Int, "QuocTichID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@TonGiaoID", SqlDbType.Int, "TonGiaoID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@SoCMND", SqlDbType.VarChar, "SoCMND", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NgayCapCMND", SqlDbType.DateTime, "NgayCapCMND", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NoiCapCMND", SqlDbType.NVarChar, "NoiCapCMND", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@SoHoChieu", SqlDbType.VarChar, "SoHoChieu", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NgayCapHoChieu", SqlDbType.DateTime, "NgayCapHoChieu", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NoiCapHoChieu", SqlDbType.NVarChar, "NoiCapHoChieu", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NgayHetHanHoChieu", SqlDbType.DateTime, "NgayHetHanHoChieu", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@ThuongTruTinhTPID", SqlDbType.Int, "ThuongTruTinhTPID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@ThuongTruQuanHuyenID", SqlDbType.Int, "ThuongTruQuanHuyenID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@ThuongTruXaPhuongID", SqlDbType.Int, "ThuongTruXaPhuongID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@ThuongTruToID", SqlDbType.Int, "ThuongTruToID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@ThuongTruDiaChi", SqlDbType.NVarChar, "ThuongTruDiaChi", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NoiOHienNayTinhTPID", SqlDbType.Int, "NoiOHienNayTinhTPID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NoiOHienNayQuanHuyenID", SqlDbType.Int, "NoiOHienNayQuanHuyenID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NoiOHienNayXaPhuongID", SqlDbType.Int, "NoiOHienNayXaPhuongID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NoiOHienNayToID", SqlDbType.Int, "NoiOHienNayToID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NoiOHienNayDiaChi", SqlDbType.NVarChar, "NoiOHienNayDiaChi", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@TrinhDoHocVanID", SqlDbType.Int, "TrinhDoHocVanID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@TrinhDoChuyenMonID", SqlDbType.Int, "TrinhDoChuyenMonID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@BietTiengDanTocID", SqlDbType.Int, "BietTiengDanTocID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@TrinhDoNgoaiNguID", SqlDbType.Int, "TrinhDoNgoaiNguID", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NgheNghiepNoiLamViec", SqlDbType.NVarChar, "NgheNghiepNoiLamViec", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@SoDienThoaiLienHe", SqlDbType.VarChar, "SoDienThoaiLienHe", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@TinhTrang", SqlDbType.Int, "TinhTrang", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NgayChuyenDen", SqlDbType.DateTime, "NgayChuyenDen", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NoiThuongTruTruocChuyenDen", SqlDbType.NVarChar, "NoiThuongTruTruocChuyenDen", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NgayChuyenDi", SqlDbType.DateTime, "NgayChuyenDi", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NoiChuyenDen", SqlDbType.NVarChar, "NoiChuyenDen", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@NgayMat", SqlDbType.DateTime, "NgayMat", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@IsDelete", SqlDbType.Bit, "IsDelete", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@LyDoXoaDangKyThuongTru", SqlDbType.NVarChar, "LyDoXoaDangKyThuongTru", DataRowVersion.Current);
			db.AddInParameter(InsertCommand, "@HoKhauID", SqlDbType.Int, "HoKhauID", DataRowVersion.Current);

            System.Data.Common.DbCommand UpdateCommand = db.GetSqlStringCommand(update);
			db.AddInParameter(UpdateCommand, "@ID", SqlDbType.BigInt, "ID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@MaNhanKhau", SqlDbType.VarChar, "MaNhanKhau", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@HoLot", SqlDbType.NVarChar, "HoLot", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@Ten", SqlDbType.NVarChar, "Ten", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@TenGoiKhac", SqlDbType.NVarChar, "TenGoiKhac", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@GioiTinh", SqlDbType.Int, "GioiTinh", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@LaChuHo", SqlDbType.Bit, "LaChuHo", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@QuanHeVoiChuHoID", SqlDbType.Int, "QuanHeVoiChuHoID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NgaySinh", SqlDbType.Int, "NgaySinh", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@ThangSinh", SqlDbType.Int, "ThangSinh", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NamSinh", SqlDbType.Int, "NamSinh", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NoiSinh", SqlDbType.NVarChar, "NoiSinh", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@QueQuanTinhTPID", SqlDbType.Int, "QueQuanTinhTPID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@QueQuanQuanHuyenID", SqlDbType.Int, "QueQuanQuanHuyenID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@QueQuanXaPhuongID", SqlDbType.Int, "QueQuanXaPhuongID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@QueQuanToID", SqlDbType.Int, "QueQuanToID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@DanTocID", SqlDbType.Int, "DanTocID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@QuocTichID", SqlDbType.Int, "QuocTichID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@TonGiaoID", SqlDbType.Int, "TonGiaoID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@SoCMND", SqlDbType.VarChar, "SoCMND", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NgayCapCMND", SqlDbType.DateTime, "NgayCapCMND", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NoiCapCMND", SqlDbType.NVarChar, "NoiCapCMND", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@SoHoChieu", SqlDbType.VarChar, "SoHoChieu", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NgayCapHoChieu", SqlDbType.DateTime, "NgayCapHoChieu", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NoiCapHoChieu", SqlDbType.NVarChar, "NoiCapHoChieu", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NgayHetHanHoChieu", SqlDbType.DateTime, "NgayHetHanHoChieu", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@ThuongTruTinhTPID", SqlDbType.Int, "ThuongTruTinhTPID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@ThuongTruQuanHuyenID", SqlDbType.Int, "ThuongTruQuanHuyenID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@ThuongTruXaPhuongID", SqlDbType.Int, "ThuongTruXaPhuongID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@ThuongTruToID", SqlDbType.Int, "ThuongTruToID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@ThuongTruDiaChi", SqlDbType.NVarChar, "ThuongTruDiaChi", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NoiOHienNayTinhTPID", SqlDbType.Int, "NoiOHienNayTinhTPID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NoiOHienNayQuanHuyenID", SqlDbType.Int, "NoiOHienNayQuanHuyenID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NoiOHienNayXaPhuongID", SqlDbType.Int, "NoiOHienNayXaPhuongID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NoiOHienNayToID", SqlDbType.Int, "NoiOHienNayToID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NoiOHienNayDiaChi", SqlDbType.NVarChar, "NoiOHienNayDiaChi", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@TrinhDoHocVanID", SqlDbType.Int, "TrinhDoHocVanID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@TrinhDoChuyenMonID", SqlDbType.Int, "TrinhDoChuyenMonID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@BietTiengDanTocID", SqlDbType.Int, "BietTiengDanTocID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@TrinhDoNgoaiNguID", SqlDbType.Int, "TrinhDoNgoaiNguID", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NgheNghiepNoiLamViec", SqlDbType.NVarChar, "NgheNghiepNoiLamViec", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@SoDienThoaiLienHe", SqlDbType.VarChar, "SoDienThoaiLienHe", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@TinhTrang", SqlDbType.Int, "TinhTrang", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NgayChuyenDen", SqlDbType.DateTime, "NgayChuyenDen", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NoiThuongTruTruocChuyenDen", SqlDbType.NVarChar, "NoiThuongTruTruocChuyenDen", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NgayChuyenDi", SqlDbType.DateTime, "NgayChuyenDi", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NoiChuyenDen", SqlDbType.NVarChar, "NoiChuyenDen", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@NgayMat", SqlDbType.DateTime, "NgayMat", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@IsDelete", SqlDbType.Bit, "IsDelete", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@LyDoXoaDangKyThuongTru", SqlDbType.NVarChar, "LyDoXoaDangKyThuongTru", DataRowVersion.Current);
			db.AddInParameter(UpdateCommand, "@HoKhauID", SqlDbType.Int, "HoKhauID", DataRowVersion.Current);
			
            System.Data.Common.DbCommand DeleteCommand = db.GetSqlStringCommand(delete);
			db.AddInParameter(DeleteCommand, "@ID", SqlDbType.BigInt, "ID", DataRowVersion.Current);

            db.UpdateDataSet(ds, tableName, InsertCommand, UpdateCommand, DeleteCommand, UpdateBehavior.Standard);
        }

		#endregion
		
		//---------------------------------------------------------------------------------------------
		
		#region Select methods.
		
		public static NhanKhau Load(long iD)
		{
			const string spName = "[dbo].[p_NhanKhau_Load.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
			SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
			db.AddInParameter(dbCommand, "@ID", SqlDbType.BigInt, iD);
            IDataReader reader = db.ExecuteReader(dbCommand);
			List<NhanKhau> collection = ConvertToCollection(reader);	
			if (collection.Count > 0)
			{
				return collection[0];
			}
			return null;
		}		
		
		//---------------------------------------------------------------------------------------------
		public static List<NhanKhau> SelectCollectionAll()
		{
			IDataReader reader = SelectReaderAll();
			return ConvertToCollection(reader);			
		}		
		
		//---------------------------------------------------------------------------------------------
		
		public static List<NhanKhau> SelectCollectionDynamic(string whereCondition, string orderByExpression)
		{
			IDataReader reader = SelectReaderDynamic(whereCondition, orderByExpression);
			return ConvertToCollection(reader);		
		}
		
		//---------------------------------------------------------------------------------------------
		
		// Select by foreign key return collection		
		public static List<NhanKhau> SelectCollectionBy_DanTocID(int danTocID)
		{
            IDataReader reader = SelectReaderBy_DanTocID(danTocID);
			return ConvertToCollection(reader);	
		}		
		//---------------------------------------------------------------------------------------------
		public static List<NhanKhau> SelectCollectionBy_QuocTichID(int quocTichID)
		{
            IDataReader reader = SelectReaderBy_QuocTichID(quocTichID);
			return ConvertToCollection(reader);	
		}		
		//---------------------------------------------------------------------------------------------
		public static List<NhanKhau> SelectCollectionBy_TonGiaoID(int tonGiaoID)
		{
            IDataReader reader = SelectReaderBy_TonGiaoID(tonGiaoID);
			return ConvertToCollection(reader);	
		}		
		//---------------------------------------------------------------------------------------------
		public static List<NhanKhau> SelectCollectionBy_TrinhDoChuyenMonID(int trinhDoChuyenMonID)
		{
            IDataReader reader = SelectReaderBy_TrinhDoChuyenMonID(trinhDoChuyenMonID);
			return ConvertToCollection(reader);	
		}		
		//---------------------------------------------------------------------------------------------
		public static List<NhanKhau> SelectCollectionBy_TrinhDoHocVanID(int trinhDoHocVanID)
		{
            IDataReader reader = SelectReaderBy_TrinhDoHocVanID(trinhDoHocVanID);
			return ConvertToCollection(reader);	
		}		
		//---------------------------------------------------------------------------------------------
		public static List<NhanKhau> SelectCollectionBy_TrinhDoNgoaiNguID(int trinhDoNgoaiNguID)
		{
            IDataReader reader = SelectReaderBy_TrinhDoNgoaiNguID(trinhDoNgoaiNguID);
			return ConvertToCollection(reader);	
		}		
		//---------------------------------------------------------------------------------------------
		public static List<NhanKhau> SelectCollectionBy_HoKhauID(int hoKhauID)
		{
            IDataReader reader = SelectReaderBy_HoKhauID(hoKhauID);
			return ConvertToCollection(reader);	
		}		
		//---------------------------------------------------------------------------------------------
		
		public static DataSet SelectBy_DanTocID(int danTocID)
		{
			const string spName = "[dbo].[p_NhanKhau_SelectBy_DanTocID.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
			db.AddInParameter(dbCommand, "@DanTocID", SqlDbType.Int, danTocID);
						
            return db.ExecuteDataSet(dbCommand);
		}
		//---------------------------------------------------------------------------------------------
		public static DataSet SelectBy_QuocTichID(int quocTichID)
		{
			const string spName = "[dbo].[p_NhanKhau_SelectBy_QuocTichID.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
			db.AddInParameter(dbCommand, "@QuocTichID", SqlDbType.Int, quocTichID);
						
            return db.ExecuteDataSet(dbCommand);
		}
		//---------------------------------------------------------------------------------------------
		public static DataSet SelectBy_TonGiaoID(int tonGiaoID)
		{
			const string spName = "[dbo].[p_NhanKhau_SelectBy_TonGiaoID.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
			db.AddInParameter(dbCommand, "@TonGiaoID", SqlDbType.Int, tonGiaoID);
						
            return db.ExecuteDataSet(dbCommand);
		}
		//---------------------------------------------------------------------------------------------
		public static DataSet SelectBy_TrinhDoChuyenMonID(int trinhDoChuyenMonID)
		{
			const string spName = "[dbo].[p_NhanKhau_SelectBy_TrinhDoChuyenMonID.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
			db.AddInParameter(dbCommand, "@TrinhDoChuyenMonID", SqlDbType.Int, trinhDoChuyenMonID);
						
            return db.ExecuteDataSet(dbCommand);
		}
		//---------------------------------------------------------------------------------------------
		public static DataSet SelectBy_TrinhDoHocVanID(int trinhDoHocVanID)
		{
			const string spName = "[dbo].[p_NhanKhau_SelectBy_TrinhDoHocVanID.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
			db.AddInParameter(dbCommand, "@TrinhDoHocVanID", SqlDbType.Int, trinhDoHocVanID);
						
            return db.ExecuteDataSet(dbCommand);
		}
		//---------------------------------------------------------------------------------------------
		public static DataSet SelectBy_TrinhDoNgoaiNguID(int trinhDoNgoaiNguID)
		{
			const string spName = "[dbo].[p_NhanKhau_SelectBy_TrinhDoNgoaiNguID.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
			db.AddInParameter(dbCommand, "@TrinhDoNgoaiNguID", SqlDbType.Int, trinhDoNgoaiNguID);
						
            return db.ExecuteDataSet(dbCommand);
		}
		//---------------------------------------------------------------------------------------------
		public static DataSet SelectBy_HoKhauID(int hoKhauID)
		{
			const string spName = "[dbo].[p_NhanKhau_SelectBy_HoKhauID.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
			db.AddInParameter(dbCommand, "@HoKhauID", SqlDbType.Int, hoKhauID);
						
            return db.ExecuteDataSet(dbCommand);
		}
		//---------------------------------------------------------------------------------------------

		public static DataSet SelectAll()
        {
            const string spName = "[dbo].[p_NhanKhau_SelectAll.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);

			
            return db.ExecuteDataSet(dbCommand);
        }
		
		//---------------------------------------------------------------------------------------------
		
		public static DataSet SelectDynamic(string whereCondition, string orderByExpression)
		{
            const string spName = "[dbo].[p_NhanKhau_SelectDynamic.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);

			db.AddInParameter(dbCommand, "@WhereCondition", SqlDbType.NVarChar, whereCondition);
            db.AddInParameter(dbCommand, "@OrderByExpression", SqlDbType.NVarChar, orderByExpression);
            
            return db.ExecuteDataSet(dbCommand);        				
		}
		
		//---------------------------------------------------------------------------------------------
				
		public static IDataReader SelectReaderAll()
        {
            const string spName = "[dbo].[p_NhanKhau_SelectAll.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
            return db.ExecuteReader(dbCommand);
        }
		
		//---------------------------------------------------------------------------------------------
		
		public static IDataReader SelectReaderDynamic(string whereCondition, string orderByExpression)
		{
            const string spName = "[dbo].[p_NhanKhau_SelectDynamic.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);

			db.AddInParameter(dbCommand, "@WhereCondition", SqlDbType.NVarChar, whereCondition);
            db.AddInParameter(dbCommand, "@OrderByExpression", SqlDbType.NVarChar, orderByExpression);
            
            return db.ExecuteReader(dbCommand);        				
		}
		
		//---------------------------------------------------------------------------------------------
		
		// Select by foreign key return collection		
		public static IDataReader SelectReaderBy_DanTocID(int danTocID)
		{
			const string spName = "[dbo].[p_NhanKhau_SelectBy_DanTocID.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
			SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
			db.AddInParameter(dbCommand, "@DanTocID", SqlDbType.Int, danTocID);
			
            return db.ExecuteReader(dbCommand);
		}		
		//---------------------------------------------------------------------------------------------
		public static IDataReader SelectReaderBy_QuocTichID(int quocTichID)
		{
			const string spName = "[dbo].[p_NhanKhau_SelectBy_QuocTichID.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
			SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
			db.AddInParameter(dbCommand, "@QuocTichID", SqlDbType.Int, quocTichID);
			
            return db.ExecuteReader(dbCommand);
		}		
		//---------------------------------------------------------------------------------------------
		public static IDataReader SelectReaderBy_TonGiaoID(int tonGiaoID)
		{
			const string spName = "[dbo].[p_NhanKhau_SelectBy_TonGiaoID.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
			SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
			db.AddInParameter(dbCommand, "@TonGiaoID", SqlDbType.Int, tonGiaoID);
			
            return db.ExecuteReader(dbCommand);
		}		
		//---------------------------------------------------------------------------------------------
		public static IDataReader SelectReaderBy_TrinhDoChuyenMonID(int trinhDoChuyenMonID)
		{
			const string spName = "[dbo].[p_NhanKhau_SelectBy_TrinhDoChuyenMonID.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
			SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
			db.AddInParameter(dbCommand, "@TrinhDoChuyenMonID", SqlDbType.Int, trinhDoChuyenMonID);
			
            return db.ExecuteReader(dbCommand);
		}		
		//---------------------------------------------------------------------------------------------
		public static IDataReader SelectReaderBy_TrinhDoHocVanID(int trinhDoHocVanID)
		{
			const string spName = "[dbo].[p_NhanKhau_SelectBy_TrinhDoHocVanID.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
			SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
			db.AddInParameter(dbCommand, "@TrinhDoHocVanID", SqlDbType.Int, trinhDoHocVanID);
			
            return db.ExecuteReader(dbCommand);
		}		
		//---------------------------------------------------------------------------------------------
		public static IDataReader SelectReaderBy_TrinhDoNgoaiNguID(int trinhDoNgoaiNguID)
		{
			const string spName = "[dbo].[p_NhanKhau_SelectBy_TrinhDoNgoaiNguID.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
			SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
			db.AddInParameter(dbCommand, "@TrinhDoNgoaiNguID", SqlDbType.Int, trinhDoNgoaiNguID);
			
            return db.ExecuteReader(dbCommand);
		}		
		//---------------------------------------------------------------------------------------------
		public static IDataReader SelectReaderBy_HoKhauID(int hoKhauID)
		{
			const string spName = "[dbo].[p_NhanKhau_SelectBy_HoKhauID.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
			SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
			db.AddInParameter(dbCommand, "@HoKhauID", SqlDbType.Int, hoKhauID);
			
            return db.ExecuteReader(dbCommand);
		}		
		//---------------------------------------------------------------------------------------------
		
		#endregion
		
		//---------------------------------------------------------------------------------------------
		
		#region Insert methods.
		
		public static long InsertNhanKhau(string maNhanKhau, string hoLot, string ten, string tenGoiKhac, int gioiTinh, bool laChuHo, int quanHeVoiChuHoID, int ngaySinh, int thangSinh, int namSinh, string noiSinh, int queQuanTinhTPID, int queQuanQuanHuyenID, int queQuanXaPhuongID, int queQuanToID, int danTocID, int quocTichID, int tonGiaoID, string soCMND, DateTime ngayCapCMND, string noiCapCMND, string soHoChieu, DateTime ngayCapHoChieu, string noiCapHoChieu, DateTime ngayHetHanHoChieu, int thuongTruTinhTPID, int thuongTruQuanHuyenID, int thuongTruXaPhuongID, int thuongTruToID, string thuongTruDiaChi, int noiOHienNayTinhTPID, int noiOHienNayQuanHuyenID, int noiOHienNayXaPhuongID, int noiOHienNayToID, string noiOHienNayDiaChi, int trinhDoHocVanID, int trinhDoChuyenMonID, int bietTiengDanTocID, int trinhDoNgoaiNguID, string ngheNghiepNoiLamViec, string soDienThoaiLienHe, int tinhTrang, DateTime ngayChuyenDen, string noiThuongTruTruocChuyenDen, DateTime ngayChuyenDi, string noiChuyenDen, DateTime ngayMat, bool isDelete, string lyDoXoaDangKyThuongTru, int hoKhauID)
		{
			NhanKhau entity = new NhanKhau();	
            entity.MaNhanKhau = maNhanKhau;
			entity.HoLot = hoLot;
			entity.Ten = ten;
			entity.TenGoiKhac = tenGoiKhac;
			entity.GioiTinh = gioiTinh;
			entity.LaChuHo = laChuHo;
			entity.QuanHeVoiChuHoID = quanHeVoiChuHoID;
			entity.NgaySinh = ngaySinh;
			entity.ThangSinh = thangSinh;
			entity.NamSinh = namSinh;
			entity.NoiSinh = noiSinh;
			entity.QueQuanTinhTPID = queQuanTinhTPID;
			entity.QueQuanQuanHuyenID = queQuanQuanHuyenID;
			entity.QueQuanXaPhuongID = queQuanXaPhuongID;
			entity.QueQuanToID = queQuanToID;
			entity.DanTocID = danTocID;
			entity.QuocTichID = quocTichID;
			entity.TonGiaoID = tonGiaoID;
			entity.SoCMND = soCMND;
			entity.NgayCapCMND = ngayCapCMND;
			entity.NoiCapCMND = noiCapCMND;
			entity.SoHoChieu = soHoChieu;
			entity.NgayCapHoChieu = ngayCapHoChieu;
			entity.NoiCapHoChieu = noiCapHoChieu;
			entity.NgayHetHanHoChieu = ngayHetHanHoChieu;
			entity.ThuongTruTinhTPID = thuongTruTinhTPID;
			entity.ThuongTruQuanHuyenID = thuongTruQuanHuyenID;
			entity.ThuongTruXaPhuongID = thuongTruXaPhuongID;
			entity.ThuongTruToID = thuongTruToID;
			entity.ThuongTruDiaChi = thuongTruDiaChi;
			entity.NoiOHienNayTinhTPID = noiOHienNayTinhTPID;
			entity.NoiOHienNayQuanHuyenID = noiOHienNayQuanHuyenID;
			entity.NoiOHienNayXaPhuongID = noiOHienNayXaPhuongID;
			entity.NoiOHienNayToID = noiOHienNayToID;
			entity.NoiOHienNayDiaChi = noiOHienNayDiaChi;
			entity.TrinhDoHocVanID = trinhDoHocVanID;
			entity.TrinhDoChuyenMonID = trinhDoChuyenMonID;
			entity.BietTiengDanTocID = bietTiengDanTocID;
			entity.TrinhDoNgoaiNguID = trinhDoNgoaiNguID;
			entity.NgheNghiepNoiLamViec = ngheNghiepNoiLamViec;
			entity.SoDienThoaiLienHe = soDienThoaiLienHe;
			entity.TinhTrang = tinhTrang;
			entity.NgayChuyenDen = ngayChuyenDen;
			entity.NoiThuongTruTruocChuyenDen = noiThuongTruTruocChuyenDen;
			entity.NgayChuyenDi = ngayChuyenDi;
			entity.NoiChuyenDen = noiChuyenDen;
			entity.NgayMat = ngayMat;
			entity.IsDelete = isDelete;
			entity.LyDoXoaDangKyThuongTru = lyDoXoaDangKyThuongTru;
			entity.HoKhauID = hoKhauID;
			return entity.Insert();
		}
		
		public long Insert()
		{
			return this.Insert(null);
		}		
		
		//---------------------------------------------------------------------------------------------
		
		public long Insert(SqlTransaction transaction)
		{			
			const string spName = "[dbo].[p_NhanKhau_Insert.generated]";		
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);

			db.AddOutParameter(dbCommand, "@ID", SqlDbType.BigInt, 8);
			db.AddInParameter(dbCommand, "@MaNhanKhau", SqlDbType.VarChar, MaNhanKhau);
			db.AddInParameter(dbCommand, "@HoLot", SqlDbType.NVarChar, HoLot);
			db.AddInParameter(dbCommand, "@Ten", SqlDbType.NVarChar, Ten);
			db.AddInParameter(dbCommand, "@TenGoiKhac", SqlDbType.NVarChar, TenGoiKhac);
			db.AddInParameter(dbCommand, "@GioiTinh", SqlDbType.Int, GioiTinh);
			db.AddInParameter(dbCommand, "@LaChuHo", SqlDbType.Bit, LaChuHo);
			db.AddInParameter(dbCommand, "@QuanHeVoiChuHoID", SqlDbType.Int, QuanHeVoiChuHoID);
			db.AddInParameter(dbCommand, "@NgaySinh", SqlDbType.Int, NgaySinh);
			db.AddInParameter(dbCommand, "@ThangSinh", SqlDbType.Int, ThangSinh);
			db.AddInParameter(dbCommand, "@NamSinh", SqlDbType.Int, NamSinh);
			db.AddInParameter(dbCommand, "@NoiSinh", SqlDbType.NVarChar, NoiSinh);
			db.AddInParameter(dbCommand, "@QueQuanTinhTPID", SqlDbType.Int, QueQuanTinhTPID);
			db.AddInParameter(dbCommand, "@QueQuanQuanHuyenID", SqlDbType.Int, QueQuanQuanHuyenID);
			db.AddInParameter(dbCommand, "@QueQuanXaPhuongID", SqlDbType.Int, QueQuanXaPhuongID);
			db.AddInParameter(dbCommand, "@QueQuanToID", SqlDbType.Int, QueQuanToID);
			db.AddInParameter(dbCommand, "@DanTocID", SqlDbType.Int, DanTocID);
			db.AddInParameter(dbCommand, "@QuocTichID", SqlDbType.Int, QuocTichID);
			db.AddInParameter(dbCommand, "@TonGiaoID", SqlDbType.Int, TonGiaoID);
			db.AddInParameter(dbCommand, "@SoCMND", SqlDbType.VarChar, SoCMND);
			db.AddInParameter(dbCommand, "@NgayCapCMND", SqlDbType.DateTime, NgayCapCMND.Year <= 1753 ? DBNull.Value : (object) NgayCapCMND);
			db.AddInParameter(dbCommand, "@NoiCapCMND", SqlDbType.NVarChar, NoiCapCMND);
			db.AddInParameter(dbCommand, "@SoHoChieu", SqlDbType.VarChar, SoHoChieu);
			db.AddInParameter(dbCommand, "@NgayCapHoChieu", SqlDbType.DateTime, NgayCapHoChieu.Year <= 1753 ? DBNull.Value : (object) NgayCapHoChieu);
			db.AddInParameter(dbCommand, "@NoiCapHoChieu", SqlDbType.NVarChar, NoiCapHoChieu);
			db.AddInParameter(dbCommand, "@NgayHetHanHoChieu", SqlDbType.DateTime, NgayHetHanHoChieu.Year <= 1753 ? DBNull.Value : (object) NgayHetHanHoChieu);
			db.AddInParameter(dbCommand, "@ThuongTruTinhTPID", SqlDbType.Int, ThuongTruTinhTPID);
			db.AddInParameter(dbCommand, "@ThuongTruQuanHuyenID", SqlDbType.Int, ThuongTruQuanHuyenID);
			db.AddInParameter(dbCommand, "@ThuongTruXaPhuongID", SqlDbType.Int, ThuongTruXaPhuongID);
			db.AddInParameter(dbCommand, "@ThuongTruToID", SqlDbType.Int, ThuongTruToID);
			db.AddInParameter(dbCommand, "@ThuongTruDiaChi", SqlDbType.NVarChar, ThuongTruDiaChi);
			db.AddInParameter(dbCommand, "@NoiOHienNayTinhTPID", SqlDbType.Int, NoiOHienNayTinhTPID);
			db.AddInParameter(dbCommand, "@NoiOHienNayQuanHuyenID", SqlDbType.Int, NoiOHienNayQuanHuyenID);
			db.AddInParameter(dbCommand, "@NoiOHienNayXaPhuongID", SqlDbType.Int, NoiOHienNayXaPhuongID);
			db.AddInParameter(dbCommand, "@NoiOHienNayToID", SqlDbType.Int, NoiOHienNayToID);
			db.AddInParameter(dbCommand, "@NoiOHienNayDiaChi", SqlDbType.NVarChar, NoiOHienNayDiaChi);
			db.AddInParameter(dbCommand, "@TrinhDoHocVanID", SqlDbType.Int, TrinhDoHocVanID);
			db.AddInParameter(dbCommand, "@TrinhDoChuyenMonID", SqlDbType.Int, TrinhDoChuyenMonID);
			db.AddInParameter(dbCommand, "@BietTiengDanTocID", SqlDbType.Int, BietTiengDanTocID);
			db.AddInParameter(dbCommand, "@TrinhDoNgoaiNguID", SqlDbType.Int, TrinhDoNgoaiNguID);
			db.AddInParameter(dbCommand, "@NgheNghiepNoiLamViec", SqlDbType.NVarChar, NgheNghiepNoiLamViec);
			db.AddInParameter(dbCommand, "@SoDienThoaiLienHe", SqlDbType.VarChar, SoDienThoaiLienHe);
			db.AddInParameter(dbCommand, "@TinhTrang", SqlDbType.Int, TinhTrang);
			db.AddInParameter(dbCommand, "@NgayChuyenDen", SqlDbType.DateTime, NgayChuyenDen.Year <= 1753 ? DBNull.Value : (object) NgayChuyenDen);
			db.AddInParameter(dbCommand, "@NoiThuongTruTruocChuyenDen", SqlDbType.NVarChar, NoiThuongTruTruocChuyenDen);
			db.AddInParameter(dbCommand, "@NgayChuyenDi", SqlDbType.DateTime, NgayChuyenDi.Year <= 1753 ? DBNull.Value : (object) NgayChuyenDi);
			db.AddInParameter(dbCommand, "@NoiChuyenDen", SqlDbType.NVarChar, NoiChuyenDen);
			db.AddInParameter(dbCommand, "@NgayMat", SqlDbType.DateTime, NgayMat.Year <= 1753 ? DBNull.Value : (object) NgayMat);
			db.AddInParameter(dbCommand, "@IsDelete", SqlDbType.Bit, IsDelete);
			db.AddInParameter(dbCommand, "@LyDoXoaDangKyThuongTru", SqlDbType.NVarChar, LyDoXoaDangKyThuongTru);
			db.AddInParameter(dbCommand, "@HoKhauID", SqlDbType.Int, HoKhauID);
			
			if (transaction != null)
			{
				db.ExecuteNonQuery(dbCommand, transaction);
				ID = (long) db.GetParameterValue(dbCommand, "@ID");
				return ID;
			}
            else
			{
				db.ExecuteNonQuery(dbCommand);
				ID = (long) db.GetParameterValue(dbCommand, "@ID");
				return ID;
			}			
		}
				
		//---------------------------------------------------------------------------------------------
		public static bool InsertCollection(List<NhanKhau> collection)
        {
            bool ret;
			SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            using (SqlConnection connection = (SqlConnection)db.CreateConnection())
            {
                connection.Open();
                using(SqlTransaction transaction = connection.BeginTransaction())
				{
					try
					{
						bool ret01 = true;
						foreach (NhanKhau item in collection)
						{
							if (item.Insert(transaction) <= 0)
							{							
								ret01 = false;
								break;
							}
						}
						if (ret01)
						{
							transaction.Commit();
							ret = true;
						}
						else
						{
							transaction.Rollback();
							ret = false;                    	
						}
					}
					catch (Exception ex)
					{
						transaction.Rollback();
						throw new Exception("Error at InsertCollection method: " + ex.Message);
					}
					finally 
					{
						connection.Close();
					}
				}
            }
            return ret;		
		}
		
		#endregion
		
		//---------------------------------------------------------------------------------------------
		
		#region Insert / Update methods.
		
		public static int InsertUpdateNhanKhau(long iD, string maNhanKhau, string hoLot, string ten, string tenGoiKhac, int gioiTinh, bool laChuHo, int quanHeVoiChuHoID, int ngaySinh, int thangSinh, int namSinh, string noiSinh, int queQuanTinhTPID, int queQuanQuanHuyenID, int queQuanXaPhuongID, int queQuanToID, int danTocID, int quocTichID, int tonGiaoID, string soCMND, DateTime ngayCapCMND, string noiCapCMND, string soHoChieu, DateTime ngayCapHoChieu, string noiCapHoChieu, DateTime ngayHetHanHoChieu, int thuongTruTinhTPID, int thuongTruQuanHuyenID, int thuongTruXaPhuongID, int thuongTruToID, string thuongTruDiaChi, int noiOHienNayTinhTPID, int noiOHienNayQuanHuyenID, int noiOHienNayXaPhuongID, int noiOHienNayToID, string noiOHienNayDiaChi, int trinhDoHocVanID, int trinhDoChuyenMonID, int bietTiengDanTocID, int trinhDoNgoaiNguID, string ngheNghiepNoiLamViec, string soDienThoaiLienHe, int tinhTrang, DateTime ngayChuyenDen, string noiThuongTruTruocChuyenDen, DateTime ngayChuyenDi, string noiChuyenDen, DateTime ngayMat, bool isDelete, string lyDoXoaDangKyThuongTru, int hoKhauID)
		{
			NhanKhau entity = new NhanKhau();			
			entity.ID = iD;
			entity.MaNhanKhau = maNhanKhau;
			entity.HoLot = hoLot;
			entity.Ten = ten;
			entity.TenGoiKhac = tenGoiKhac;
			entity.GioiTinh = gioiTinh;
			entity.LaChuHo = laChuHo;
			entity.QuanHeVoiChuHoID = quanHeVoiChuHoID;
			entity.NgaySinh = ngaySinh;
			entity.ThangSinh = thangSinh;
			entity.NamSinh = namSinh;
			entity.NoiSinh = noiSinh;
			entity.QueQuanTinhTPID = queQuanTinhTPID;
			entity.QueQuanQuanHuyenID = queQuanQuanHuyenID;
			entity.QueQuanXaPhuongID = queQuanXaPhuongID;
			entity.QueQuanToID = queQuanToID;
			entity.DanTocID = danTocID;
			entity.QuocTichID = quocTichID;
			entity.TonGiaoID = tonGiaoID;
			entity.SoCMND = soCMND;
			entity.NgayCapCMND = ngayCapCMND;
			entity.NoiCapCMND = noiCapCMND;
			entity.SoHoChieu = soHoChieu;
			entity.NgayCapHoChieu = ngayCapHoChieu;
			entity.NoiCapHoChieu = noiCapHoChieu;
			entity.NgayHetHanHoChieu = ngayHetHanHoChieu;
			entity.ThuongTruTinhTPID = thuongTruTinhTPID;
			entity.ThuongTruQuanHuyenID = thuongTruQuanHuyenID;
			entity.ThuongTruXaPhuongID = thuongTruXaPhuongID;
			entity.ThuongTruToID = thuongTruToID;
			entity.ThuongTruDiaChi = thuongTruDiaChi;
			entity.NoiOHienNayTinhTPID = noiOHienNayTinhTPID;
			entity.NoiOHienNayQuanHuyenID = noiOHienNayQuanHuyenID;
			entity.NoiOHienNayXaPhuongID = noiOHienNayXaPhuongID;
			entity.NoiOHienNayToID = noiOHienNayToID;
			entity.NoiOHienNayDiaChi = noiOHienNayDiaChi;
			entity.TrinhDoHocVanID = trinhDoHocVanID;
			entity.TrinhDoChuyenMonID = trinhDoChuyenMonID;
			entity.BietTiengDanTocID = bietTiengDanTocID;
			entity.TrinhDoNgoaiNguID = trinhDoNgoaiNguID;
			entity.NgheNghiepNoiLamViec = ngheNghiepNoiLamViec;
			entity.SoDienThoaiLienHe = soDienThoaiLienHe;
			entity.TinhTrang = tinhTrang;
			entity.NgayChuyenDen = ngayChuyenDen;
			entity.NoiThuongTruTruocChuyenDen = noiThuongTruTruocChuyenDen;
			entity.NgayChuyenDi = ngayChuyenDi;
			entity.NoiChuyenDen = noiChuyenDen;
			entity.NgayMat = ngayMat;
			entity.IsDelete = isDelete;
			entity.LyDoXoaDangKyThuongTru = lyDoXoaDangKyThuongTru;
			entity.HoKhauID = hoKhauID;
			return entity.InsertUpdate();
		}
		
		//---------------------------------------------------------------------------------------------
		
		public int InsertUpdate()
		{
			return this.InsertUpdate(null);
		}
		
		//---------------------------------------------------------------------------------------------

		public int InsertUpdate(SqlTransaction transaction)
		{			
			const string spName = "[dbo].p_NhanKhau_InsertUpdate.generated]";		
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
			SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);

			db.AddInParameter(dbCommand, "@ID", SqlDbType.BigInt, ID);
			db.AddInParameter(dbCommand, "@MaNhanKhau", SqlDbType.VarChar, MaNhanKhau);
			db.AddInParameter(dbCommand, "@HoLot", SqlDbType.NVarChar, HoLot);
			db.AddInParameter(dbCommand, "@Ten", SqlDbType.NVarChar, Ten);
			db.AddInParameter(dbCommand, "@TenGoiKhac", SqlDbType.NVarChar, TenGoiKhac);
			db.AddInParameter(dbCommand, "@GioiTinh", SqlDbType.Int, GioiTinh);
			db.AddInParameter(dbCommand, "@LaChuHo", SqlDbType.Bit, LaChuHo);
			db.AddInParameter(dbCommand, "@QuanHeVoiChuHoID", SqlDbType.Int, QuanHeVoiChuHoID);
			db.AddInParameter(dbCommand, "@NgaySinh", SqlDbType.Int, NgaySinh);
			db.AddInParameter(dbCommand, "@ThangSinh", SqlDbType.Int, ThangSinh);
			db.AddInParameter(dbCommand, "@NamSinh", SqlDbType.Int, NamSinh);
			db.AddInParameter(dbCommand, "@NoiSinh", SqlDbType.NVarChar, NoiSinh);
			db.AddInParameter(dbCommand, "@QueQuanTinhTPID", SqlDbType.Int, QueQuanTinhTPID);
			db.AddInParameter(dbCommand, "@QueQuanQuanHuyenID", SqlDbType.Int, QueQuanQuanHuyenID);
			db.AddInParameter(dbCommand, "@QueQuanXaPhuongID", SqlDbType.Int, QueQuanXaPhuongID);
			db.AddInParameter(dbCommand, "@QueQuanToID", SqlDbType.Int, QueQuanToID);
			db.AddInParameter(dbCommand, "@DanTocID", SqlDbType.Int, DanTocID);
			db.AddInParameter(dbCommand, "@QuocTichID", SqlDbType.Int, QuocTichID);
			db.AddInParameter(dbCommand, "@TonGiaoID", SqlDbType.Int, TonGiaoID);
			db.AddInParameter(dbCommand, "@SoCMND", SqlDbType.VarChar, SoCMND);
			db.AddInParameter(dbCommand, "@NgayCapCMND", SqlDbType.DateTime, NgayCapCMND.Year <= 1753 ? DBNull.Value : (object) NgayCapCMND);
			db.AddInParameter(dbCommand, "@NoiCapCMND", SqlDbType.NVarChar, NoiCapCMND);
			db.AddInParameter(dbCommand, "@SoHoChieu", SqlDbType.VarChar, SoHoChieu);
			db.AddInParameter(dbCommand, "@NgayCapHoChieu", SqlDbType.DateTime, NgayCapHoChieu.Year <= 1753 ? DBNull.Value : (object) NgayCapHoChieu);
			db.AddInParameter(dbCommand, "@NoiCapHoChieu", SqlDbType.NVarChar, NoiCapHoChieu);
			db.AddInParameter(dbCommand, "@NgayHetHanHoChieu", SqlDbType.DateTime, NgayHetHanHoChieu.Year <= 1753 ? DBNull.Value : (object) NgayHetHanHoChieu);
			db.AddInParameter(dbCommand, "@ThuongTruTinhTPID", SqlDbType.Int, ThuongTruTinhTPID);
			db.AddInParameter(dbCommand, "@ThuongTruQuanHuyenID", SqlDbType.Int, ThuongTruQuanHuyenID);
			db.AddInParameter(dbCommand, "@ThuongTruXaPhuongID", SqlDbType.Int, ThuongTruXaPhuongID);
			db.AddInParameter(dbCommand, "@ThuongTruToID", SqlDbType.Int, ThuongTruToID);
			db.AddInParameter(dbCommand, "@ThuongTruDiaChi", SqlDbType.NVarChar, ThuongTruDiaChi);
			db.AddInParameter(dbCommand, "@NoiOHienNayTinhTPID", SqlDbType.Int, NoiOHienNayTinhTPID);
			db.AddInParameter(dbCommand, "@NoiOHienNayQuanHuyenID", SqlDbType.Int, NoiOHienNayQuanHuyenID);
			db.AddInParameter(dbCommand, "@NoiOHienNayXaPhuongID", SqlDbType.Int, NoiOHienNayXaPhuongID);
			db.AddInParameter(dbCommand, "@NoiOHienNayToID", SqlDbType.Int, NoiOHienNayToID);
			db.AddInParameter(dbCommand, "@NoiOHienNayDiaChi", SqlDbType.NVarChar, NoiOHienNayDiaChi);
			db.AddInParameter(dbCommand, "@TrinhDoHocVanID", SqlDbType.Int, TrinhDoHocVanID);
			db.AddInParameter(dbCommand, "@TrinhDoChuyenMonID", SqlDbType.Int, TrinhDoChuyenMonID);
			db.AddInParameter(dbCommand, "@BietTiengDanTocID", SqlDbType.Int, BietTiengDanTocID);
			db.AddInParameter(dbCommand, "@TrinhDoNgoaiNguID", SqlDbType.Int, TrinhDoNgoaiNguID);
			db.AddInParameter(dbCommand, "@NgheNghiepNoiLamViec", SqlDbType.NVarChar, NgheNghiepNoiLamViec);
			db.AddInParameter(dbCommand, "@SoDienThoaiLienHe", SqlDbType.VarChar, SoDienThoaiLienHe);
			db.AddInParameter(dbCommand, "@TinhTrang", SqlDbType.Int, TinhTrang);
			db.AddInParameter(dbCommand, "@NgayChuyenDen", SqlDbType.DateTime, NgayChuyenDen.Year <= 1753 ? DBNull.Value : (object) NgayChuyenDen);
			db.AddInParameter(dbCommand, "@NoiThuongTruTruocChuyenDen", SqlDbType.NVarChar, NoiThuongTruTruocChuyenDen);
			db.AddInParameter(dbCommand, "@NgayChuyenDi", SqlDbType.DateTime, NgayChuyenDi.Year <= 1753 ? DBNull.Value : (object) NgayChuyenDi);
			db.AddInParameter(dbCommand, "@NoiChuyenDen", SqlDbType.NVarChar, NoiChuyenDen);
			db.AddInParameter(dbCommand, "@NgayMat", SqlDbType.DateTime, NgayMat.Year <= 1753 ? DBNull.Value : (object) NgayMat);
			db.AddInParameter(dbCommand, "@IsDelete", SqlDbType.Bit, IsDelete);
			db.AddInParameter(dbCommand, "@LyDoXoaDangKyThuongTru", SqlDbType.NVarChar, LyDoXoaDangKyThuongTru);
			db.AddInParameter(dbCommand, "@HoKhauID", SqlDbType.Int, HoKhauID);
			
			if (transaction != null)
                return db.ExecuteNonQuery(dbCommand, transaction);
            else
                return db.ExecuteNonQuery(dbCommand);			
		}
		
		//---------------------------------------------------------------------------------------------
		public static bool InsertUpdateCollection(List<NhanKhau> collection)
        {
            bool ret;
			SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            using (SqlConnection connection = (SqlConnection)db.CreateConnection())
            {
                connection.Open();
                using (SqlTransaction transaction = connection.BeginTransaction())
				{
					try
					{
						bool ret01 = true;
						foreach (NhanKhau item in collection)
						{
							if (item.InsertUpdate(transaction) <= 0)
							{
								ret01 = false;
								break;
							}
						}
						if (ret01)
						{
							transaction.Commit();
							ret = true;
						}
						else
						{
							transaction.Rollback();
							ret = false;                    	
						}
					}
					catch (Exception ex)
					{
						transaction.Rollback();
						throw new Exception("Error at InsertUpdateCollection method: " + ex.Message);
						
					}
					finally 
					{
						connection.Close();
					}
				}
            }
            return ret;		
		}	
		#endregion
		
		//---------------------------------------------------------------------------------------------
		
		#region Update methods.
		
		public static int UpdateNhanKhau(long iD, string maNhanKhau, string hoLot, string ten, string tenGoiKhac, int gioiTinh, bool laChuHo, int quanHeVoiChuHoID, int ngaySinh, int thangSinh, int namSinh, string noiSinh, int queQuanTinhTPID, int queQuanQuanHuyenID, int queQuanXaPhuongID, int queQuanToID, int danTocID, int quocTichID, int tonGiaoID, string soCMND, DateTime ngayCapCMND, string noiCapCMND, string soHoChieu, DateTime ngayCapHoChieu, string noiCapHoChieu, DateTime ngayHetHanHoChieu, int thuongTruTinhTPID, int thuongTruQuanHuyenID, int thuongTruXaPhuongID, int thuongTruToID, string thuongTruDiaChi, int noiOHienNayTinhTPID, int noiOHienNayQuanHuyenID, int noiOHienNayXaPhuongID, int noiOHienNayToID, string noiOHienNayDiaChi, int trinhDoHocVanID, int trinhDoChuyenMonID, int bietTiengDanTocID, int trinhDoNgoaiNguID, string ngheNghiepNoiLamViec, string soDienThoaiLienHe, int tinhTrang, DateTime ngayChuyenDen, string noiThuongTruTruocChuyenDen, DateTime ngayChuyenDi, string noiChuyenDen, DateTime ngayMat, bool isDelete, string lyDoXoaDangKyThuongTru, int hoKhauID)
		{
			NhanKhau entity = new NhanKhau();			
			entity.ID = iD;
			entity.MaNhanKhau = maNhanKhau;
			entity.HoLot = hoLot;
			entity.Ten = ten;
			entity.TenGoiKhac = tenGoiKhac;
			entity.GioiTinh = gioiTinh;
			entity.LaChuHo = laChuHo;
			entity.QuanHeVoiChuHoID = quanHeVoiChuHoID;
			entity.NgaySinh = ngaySinh;
			entity.ThangSinh = thangSinh;
			entity.NamSinh = namSinh;
			entity.NoiSinh = noiSinh;
			entity.QueQuanTinhTPID = queQuanTinhTPID;
			entity.QueQuanQuanHuyenID = queQuanQuanHuyenID;
			entity.QueQuanXaPhuongID = queQuanXaPhuongID;
			entity.QueQuanToID = queQuanToID;
			entity.DanTocID = danTocID;
			entity.QuocTichID = quocTichID;
			entity.TonGiaoID = tonGiaoID;
			entity.SoCMND = soCMND;
			entity.NgayCapCMND = ngayCapCMND;
			entity.NoiCapCMND = noiCapCMND;
			entity.SoHoChieu = soHoChieu;
			entity.NgayCapHoChieu = ngayCapHoChieu;
			entity.NoiCapHoChieu = noiCapHoChieu;
			entity.NgayHetHanHoChieu = ngayHetHanHoChieu;
			entity.ThuongTruTinhTPID = thuongTruTinhTPID;
			entity.ThuongTruQuanHuyenID = thuongTruQuanHuyenID;
			entity.ThuongTruXaPhuongID = thuongTruXaPhuongID;
			entity.ThuongTruToID = thuongTruToID;
			entity.ThuongTruDiaChi = thuongTruDiaChi;
			entity.NoiOHienNayTinhTPID = noiOHienNayTinhTPID;
			entity.NoiOHienNayQuanHuyenID = noiOHienNayQuanHuyenID;
			entity.NoiOHienNayXaPhuongID = noiOHienNayXaPhuongID;
			entity.NoiOHienNayToID = noiOHienNayToID;
			entity.NoiOHienNayDiaChi = noiOHienNayDiaChi;
			entity.TrinhDoHocVanID = trinhDoHocVanID;
			entity.TrinhDoChuyenMonID = trinhDoChuyenMonID;
			entity.BietTiengDanTocID = bietTiengDanTocID;
			entity.TrinhDoNgoaiNguID = trinhDoNgoaiNguID;
			entity.NgheNghiepNoiLamViec = ngheNghiepNoiLamViec;
			entity.SoDienThoaiLienHe = soDienThoaiLienHe;
			entity.TinhTrang = tinhTrang;
			entity.NgayChuyenDen = ngayChuyenDen;
			entity.NoiThuongTruTruocChuyenDen = noiThuongTruTruocChuyenDen;
			entity.NgayChuyenDi = ngayChuyenDi;
			entity.NoiChuyenDen = noiChuyenDen;
			entity.NgayMat = ngayMat;
			entity.IsDelete = isDelete;
			entity.LyDoXoaDangKyThuongTru = lyDoXoaDangKyThuongTru;
			entity.HoKhauID = hoKhauID;
			return entity.Update();
		}
		
		//---------------------------------------------------------------------------------------------
		
		public int Update()
		{
			return this.Update(null);
		}
		
		//---------------------------------------------------------------------------------------------

		public int Update(SqlTransaction transaction)
		{
			const string spName = "[dbo].[p_NhanKhau_Update.generated]";		
			SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
			SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);

			db.AddInParameter(dbCommand, "@ID", SqlDbType.BigInt, ID);
			db.AddInParameter(dbCommand, "@MaNhanKhau", SqlDbType.VarChar, MaNhanKhau);
			db.AddInParameter(dbCommand, "@HoLot", SqlDbType.NVarChar, HoLot);
			db.AddInParameter(dbCommand, "@Ten", SqlDbType.NVarChar, Ten);
			db.AddInParameter(dbCommand, "@TenGoiKhac", SqlDbType.NVarChar, TenGoiKhac);
			db.AddInParameter(dbCommand, "@GioiTinh", SqlDbType.Int, GioiTinh);
			db.AddInParameter(dbCommand, "@LaChuHo", SqlDbType.Bit, LaChuHo);
			db.AddInParameter(dbCommand, "@QuanHeVoiChuHoID", SqlDbType.Int, QuanHeVoiChuHoID);
			db.AddInParameter(dbCommand, "@NgaySinh", SqlDbType.Int, NgaySinh);
			db.AddInParameter(dbCommand, "@ThangSinh", SqlDbType.Int, ThangSinh);
			db.AddInParameter(dbCommand, "@NamSinh", SqlDbType.Int, NamSinh);
			db.AddInParameter(dbCommand, "@NoiSinh", SqlDbType.NVarChar, NoiSinh);
			db.AddInParameter(dbCommand, "@QueQuanTinhTPID", SqlDbType.Int, QueQuanTinhTPID);
			db.AddInParameter(dbCommand, "@QueQuanQuanHuyenID", SqlDbType.Int, QueQuanQuanHuyenID);
			db.AddInParameter(dbCommand, "@QueQuanXaPhuongID", SqlDbType.Int, QueQuanXaPhuongID);
			db.AddInParameter(dbCommand, "@QueQuanToID", SqlDbType.Int, QueQuanToID);
			db.AddInParameter(dbCommand, "@DanTocID", SqlDbType.Int, DanTocID);
			db.AddInParameter(dbCommand, "@QuocTichID", SqlDbType.Int, QuocTichID);
			db.AddInParameter(dbCommand, "@TonGiaoID", SqlDbType.Int, TonGiaoID);
			db.AddInParameter(dbCommand, "@SoCMND", SqlDbType.VarChar, SoCMND);
			db.AddInParameter(dbCommand, "@NgayCapCMND", SqlDbType.DateTime, NgayCapCMND.Year <= 1753 ? DBNull.Value : (object) NgayCapCMND);
			db.AddInParameter(dbCommand, "@NoiCapCMND", SqlDbType.NVarChar, NoiCapCMND);
			db.AddInParameter(dbCommand, "@SoHoChieu", SqlDbType.VarChar, SoHoChieu);
			db.AddInParameter(dbCommand, "@NgayCapHoChieu", SqlDbType.DateTime, NgayCapHoChieu.Year <= 1753 ? DBNull.Value : (object) NgayCapHoChieu);
			db.AddInParameter(dbCommand, "@NoiCapHoChieu", SqlDbType.NVarChar, NoiCapHoChieu);
			db.AddInParameter(dbCommand, "@NgayHetHanHoChieu", SqlDbType.DateTime, NgayHetHanHoChieu.Year <= 1753 ? DBNull.Value : (object) NgayHetHanHoChieu);
			db.AddInParameter(dbCommand, "@ThuongTruTinhTPID", SqlDbType.Int, ThuongTruTinhTPID);
			db.AddInParameter(dbCommand, "@ThuongTruQuanHuyenID", SqlDbType.Int, ThuongTruQuanHuyenID);
			db.AddInParameter(dbCommand, "@ThuongTruXaPhuongID", SqlDbType.Int, ThuongTruXaPhuongID);
			db.AddInParameter(dbCommand, "@ThuongTruToID", SqlDbType.Int, ThuongTruToID);
			db.AddInParameter(dbCommand, "@ThuongTruDiaChi", SqlDbType.NVarChar, ThuongTruDiaChi);
			db.AddInParameter(dbCommand, "@NoiOHienNayTinhTPID", SqlDbType.Int, NoiOHienNayTinhTPID);
			db.AddInParameter(dbCommand, "@NoiOHienNayQuanHuyenID", SqlDbType.Int, NoiOHienNayQuanHuyenID);
			db.AddInParameter(dbCommand, "@NoiOHienNayXaPhuongID", SqlDbType.Int, NoiOHienNayXaPhuongID);
			db.AddInParameter(dbCommand, "@NoiOHienNayToID", SqlDbType.Int, NoiOHienNayToID);
			db.AddInParameter(dbCommand, "@NoiOHienNayDiaChi", SqlDbType.NVarChar, NoiOHienNayDiaChi);
			db.AddInParameter(dbCommand, "@TrinhDoHocVanID", SqlDbType.Int, TrinhDoHocVanID);
			db.AddInParameter(dbCommand, "@TrinhDoChuyenMonID", SqlDbType.Int, TrinhDoChuyenMonID);
			db.AddInParameter(dbCommand, "@BietTiengDanTocID", SqlDbType.Int, BietTiengDanTocID);
			db.AddInParameter(dbCommand, "@TrinhDoNgoaiNguID", SqlDbType.Int, TrinhDoNgoaiNguID);
			db.AddInParameter(dbCommand, "@NgheNghiepNoiLamViec", SqlDbType.NVarChar, NgheNghiepNoiLamViec);
			db.AddInParameter(dbCommand, "@SoDienThoaiLienHe", SqlDbType.VarChar, SoDienThoaiLienHe);
			db.AddInParameter(dbCommand, "@TinhTrang", SqlDbType.Int, TinhTrang);
			db.AddInParameter(dbCommand, "@NgayChuyenDen", SqlDbType.DateTime, NgayChuyenDen.Year <= 1753 ? DBNull.Value : (object) NgayChuyenDen);
			db.AddInParameter(dbCommand, "@NoiThuongTruTruocChuyenDen", SqlDbType.NVarChar, NoiThuongTruTruocChuyenDen);
			db.AddInParameter(dbCommand, "@NgayChuyenDi", SqlDbType.DateTime, NgayChuyenDi.Year <= 1753 ? DBNull.Value : (object) NgayChuyenDi);
			db.AddInParameter(dbCommand, "@NoiChuyenDen", SqlDbType.NVarChar, NoiChuyenDen);
			db.AddInParameter(dbCommand, "@NgayMat", SqlDbType.DateTime, NgayMat.Year <= 1753 ? DBNull.Value : (object) NgayMat);
			db.AddInParameter(dbCommand, "@IsDelete", SqlDbType.Bit, IsDelete);
			db.AddInParameter(dbCommand, "@LyDoXoaDangKyThuongTru", SqlDbType.NVarChar, LyDoXoaDangKyThuongTru);
			db.AddInParameter(dbCommand, "@HoKhauID", SqlDbType.Int, HoKhauID);
			
			if (transaction != null)
                return db.ExecuteNonQuery(dbCommand, transaction);
            else
                return db.ExecuteNonQuery(dbCommand);
		}
				
		//---------------------------------------------------------------------------------------------
		public static bool UpdateCollection(List<NhanKhau> collection)
        {
            bool ret;
			SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            using (SqlConnection connection = (SqlConnection)db.CreateConnection())
            {
                connection.Open();
                using (SqlTransaction transaction = connection.BeginTransaction())
				{
					try
					{
						bool ret01 = true;
						foreach (NhanKhau item in collection)
						{
							if (item.Update(transaction) <= 0)
							{
								ret01 = false;
								break;
							}
						}
						if (ret01)
						{
							transaction.Commit();
							ret = true;
						}
						else
						{
							transaction.Rollback();
							ret = false;                    	
						}
					}
					catch (Exception ex)
					{
						transaction.Rollback();
						throw new Exception("Error at UpdateCollection method: " + ex.Message);
					}
					finally 
					{
						connection.Close();
					}
				}
            }
            return ret;		
		}
		
		#endregion
		
		//---------------------------------------------------------------------------------------------
		
		#region Delete methods.
		
		public static int DeleteNhanKhau(long iD)
		{
			NhanKhau entity = new NhanKhau();
			entity.ID = iD;
			
			return entity.Delete();
		}
		
		public int Delete()
		{
			return this.Delete(null);
		}
		
		//---------------------------------------------------------------------------------------------

		public int Delete(SqlTransaction transaction)
		{
			const string spName = "[dbo].[p_NhanKhau_Delete.generated]";		
			SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
			SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
			db.AddInParameter(dbCommand, "@ID", SqlDbType.BigInt, ID);
			
			if (transaction != null)
                return db.ExecuteNonQuery(dbCommand, transaction);
            else
                return db.ExecuteNonQuery(dbCommand);
		}
		
		//---------------------------------------------------------------------------------------------
		
		public static int DeleteBy_DanTocID(int danTocID)
		{
			const string spName = "[dbo].[p_NhanKhau_DeleteBy_DanTocID.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
			db.AddInParameter(dbCommand, "@DanTocID", SqlDbType.Int, danTocID);
						
            return db.ExecuteNonQuery(dbCommand);
		}
		
		//---------------------------------------------------------------------------------------------
			
		public static int DeleteBy_QuocTichID(int quocTichID)
		{
			const string spName = "[dbo].[p_NhanKhau_DeleteBy_QuocTichID.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
			db.AddInParameter(dbCommand, "@QuocTichID", SqlDbType.Int, quocTichID);
						
            return db.ExecuteNonQuery(dbCommand);
		}
		
		//---------------------------------------------------------------------------------------------
			
		public static int DeleteBy_TonGiaoID(int tonGiaoID)
		{
			const string spName = "[dbo].[p_NhanKhau_DeleteBy_TonGiaoID.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
			db.AddInParameter(dbCommand, "@TonGiaoID", SqlDbType.Int, tonGiaoID);
						
            return db.ExecuteNonQuery(dbCommand);
		}
		
		//---------------------------------------------------------------------------------------------
			
		public static int DeleteBy_TrinhDoChuyenMonID(int trinhDoChuyenMonID)
		{
			const string spName = "[dbo].[p_NhanKhau_DeleteBy_TrinhDoChuyenMonID.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
			db.AddInParameter(dbCommand, "@TrinhDoChuyenMonID", SqlDbType.Int, trinhDoChuyenMonID);
						
            return db.ExecuteNonQuery(dbCommand);
		}
		
		//---------------------------------------------------------------------------------------------
			
		public static int DeleteBy_TrinhDoHocVanID(int trinhDoHocVanID)
		{
			const string spName = "[dbo].[p_NhanKhau_DeleteBy_TrinhDoHocVanID.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
			db.AddInParameter(dbCommand, "@TrinhDoHocVanID", SqlDbType.Int, trinhDoHocVanID);
						
            return db.ExecuteNonQuery(dbCommand);
		}
		
		//---------------------------------------------------------------------------------------------
			
		public static int DeleteBy_TrinhDoNgoaiNguID(int trinhDoNgoaiNguID)
		{
			const string spName = "[dbo].[p_NhanKhau_DeleteBy_TrinhDoNgoaiNguID.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
			db.AddInParameter(dbCommand, "@TrinhDoNgoaiNguID", SqlDbType.Int, trinhDoNgoaiNguID);
						
            return db.ExecuteNonQuery(dbCommand);
		}
		
		//---------------------------------------------------------------------------------------------
			
		public static int DeleteBy_HoKhauID(int hoKhauID)
		{
			const string spName = "[dbo].[p_NhanKhau_DeleteBy_HoKhauID.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);
			
			db.AddInParameter(dbCommand, "@HoKhauID", SqlDbType.Int, hoKhauID);
						
            return db.ExecuteNonQuery(dbCommand);
		}
		
		//---------------------------------------------------------------------------------------------
			
		
		public static int DeleteDynamic(string whereCondition)
		{
			const string spName = "[dbo].[p_NhanKhau_DeleteDynamic.generated]";
            SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            SqlCommand dbCommand = (SqlCommand) db.GetStoredProcCommand(spName);

			db.AddInParameter(dbCommand, "@WhereCondition", SqlDbType.NVarChar, whereCondition);
            
            return db.ExecuteNonQuery(dbCommand);   
		}
		//---------------------------------------------------------------------------------------------
		
		public static bool DeleteCollection(List<NhanKhau> collection)
        {
            bool ret;
			SqlDatabase db = (SqlDatabase) DatabaseFactory.CreateDatabase();
            using (SqlConnection connection = (SqlConnection)db.CreateConnection())
            {
                connection.Open();
                using (SqlTransaction transaction = connection.BeginTransaction())
				{
					try
					{
						bool ret01 = true;
						foreach (NhanKhau item in collection)
						{
							if (item.Delete(transaction) <= 0)
							{
								ret01 = false;
								break;
							}
						}
						if (ret01)
						{
							transaction.Commit();
							ret = true;
						}
						else
						{
							transaction.Rollback();
							ret = false;                    	
						}
					}
					catch (Exception ex)
					{
						transaction.Rollback();
						throw new Exception("Error at DeleteCollection method: " + ex.Message);
					}
					finally 
					{
						connection.Close();
					}
				}
            }
            return ret;		
		}
		#endregion
		
        //---------------------------------------------------------------------------------------------
		
        #region ICloneable Members

        public object Clone()
        {
            return base.MemberwiseClone();
        }

        public NhanKhau CloneObject()
        {
            return this.Clone() as NhanKhau;
        }
        
        #endregion
	}	
}